Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve rectangular domain module code in Dyno #25684

Merged
merged 66 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
5021a65
Move 'init' call comment closer to where it's created
riftEmber Aug 1, 2024
d70cc1d
Rewrite 'new dmap' to 'new _distribution'
riftEmber Aug 1, 2024
8edb2bf
Add 'new' resolution for domains
riftEmber Jul 31, 2024
6f4ad16
Replace hardcoded IDs of special records in return-type-inference
riftEmber Jul 31, 2024
1c7008f
Remove more redundant hardcoded symbol names of special types
riftEmber Jul 31, 2024
cf2b217
Assert domain is domain type in testDomains
riftEmber Aug 2, 2024
87ec0d2
Rewrite resolveSpecialCall if/else as a short-circuiting disjunction
riftEmber Aug 5, 2024
4c7740b
Add 'domain' case to resolveSpecialKeywordCall
riftEmber Aug 6, 2024
6b7b8b7
Resolve 'domain(?)' as 'domain'
riftEmber Aug 6, 2024
b9146f6
Pass 'dist' arg with placeholder type
riftEmber Aug 6, 2024
9324e57
Resolve and use real 'defaultDist' type
riftEmber Aug 6, 2024
8882ea2
Move instead of copy actuals
riftEmber Aug 21, 2024
3e34e15
Switch domain resolve from chpl__buildDomainRuntimeType to new _domain
riftEmber Aug 21, 2024
2b56b7f
More work on getting new _domain working
riftEmber Aug 21, 2024
f4d7694
Add TODO to put runAndTrackErrors back
riftEmber Aug 23, 2024
983353f
Remove leftover breakpoints
riftEmber Aug 23, 2024
882b31c
Use init call as type rather than value
riftEmber Aug 23, 2024
8830b08
Add domain literal type resolution
riftEmber Aug 23, 2024
e879d16
Fix comment about object -> RootClass
riftEmber Sep 4, 2024
8791772
Set up ctFromSubs for _domain
riftEmber Sep 4, 2024
118ce04
Set INIT_RECEIVER kind for generated _domain.init call
riftEmber Sep 4, 2024
8b1c6f1
Include _instance in DomainType subsittutions to fix init issue
riftEmber Sep 9, 2024
d87d10f
Fix resolving domain type expressions via resolved init receiver
riftEmber Sep 9, 2024
d5c55e4
Restore use of runAndTrackErrors
riftEmber Sep 9, 2024
ac32f9a
Get basic testing with standard domain module
riftEmber Sep 9, 2024
95750d7
Update testing from stridable -> strides
riftEmber Sep 9, 2024
7b0b72c
Add and use RUNTIME_TYPE AssociatedAction for domain type expressions
riftEmber Sep 10, 2024
b65005d
Remove compiler-generated domain methods
riftEmber Sep 10, 2024
2a64008
Re-enable testing for some basic domain methods
riftEmber Sep 10, 2024
58a7cbb
Re-enable testDomains .type testing
riftEmber Sep 10, 2024
c5c90a3
Enable forwarding on DomainTypes
riftEmber Sep 13, 2024
049bcbb
Adjust and re-enable _domain.pid testing
riftEmber Sep 13, 2024
5ec7563
Re-enable domain iteration testing
riftEmber Sep 13, 2024
15e4ec3
Remove unused variable
riftEmber Sep 16, 2024
2ec8b66
Remove use of minimal ChapelArray in testArrays
riftEmber Sep 16, 2024
ba91b1f
Revert "Remove use of minimal ChapelArray in testArrays"
riftEmber Sep 16, 2024
72b1bb6
Use real ChapelDomain in testArrays, with module code errors ignored
riftEmber Sep 16, 2024
1de785f
Add getGenericType branch for DomainType
riftEmber Sep 26, 2024
f2ac562
Skip type resolving domain literals for scopeResolveOnly
riftEmber Sep 30, 2024
8e820a7
Use helper for owned/shared record IDs
riftEmber Sep 30, 2024
054155d
Remove previous, commented domain resolution code
riftEmber Oct 1, 2024
28dbe5f
Refactor and test to gracefully error, even with no modules
riftEmber Oct 1, 2024
1154969
Also test proper errors with standard modules
riftEmber Oct 1, 2024
340b548
Re-enable error checking in testArrays
riftEmber Oct 1, 2024
cc74c72
Refactor domain ctFromSubs branch into helper
riftEmber Oct 3, 2024
2b1230c
Use fieldsForTypeDecl for domain subs, validate types
riftEmber Oct 3, 2024
08be904
Rename DomainType stridable->strides
riftEmber Oct 3, 2024
73fa259
Remove return-type-inference for (non-existent) compiler-generated do…
riftEmber Oct 3, 2024
ec55c8d
Use CHPL_TYPE_ERROR macro
riftEmber Oct 3, 2024
1848c41
Merge resolveNewFor{Record,Domain,Union}->RecordLike
riftEmber Oct 3, 2024
8300a0c
Fix repeated "however" in error message
riftEmber Oct 3, 2024
2494c93
Make getSymbolFromTopLevelModule also return sym name
riftEmber Oct 4, 2024
f47c972
Remove _domain type alias
riftEmber Oct 4, 2024
f7241a7
Use buildStdContext helper in domain tests
riftEmber Oct 4, 2024
4c87aea
Use realizeErrors properly in array/domain tests
riftEmber Oct 4, 2024
2558474
Re-enable rectangular domain canpass and index(D) tests
riftEmber Oct 4, 2024
4239120
Remove unused minimal testing version of ChapelDomain
riftEmber Oct 4, 2024
f9c1d7b
Reuse context in testDomains for performance
riftEmber Oct 4, 2024
d6c25fc
Refactor getDefaultDistType to not create meaningless ID
riftEmber Oct 4, 2024
aebf86f
Remove misleading comment in minimal ChapelArray
riftEmber Oct 4, 2024
afb862c
Merge branch 'main' into dyno-builddomainruntimetype
riftEmber Oct 7, 2024
5451a8c
Fix weird indentation
riftEmber Oct 7, 2024
50f3e07
Add BaseSparseDom in BaseDom subclasses list
riftEmber Oct 7, 2024
5390fff
Check domain class IDs rather than names
riftEmber Oct 7, 2024
6770f17
Move dmap->_distribution closer to other adjustments
riftEmber Oct 7, 2024
f8b3d77
Replace assert with returning default value
riftEmber Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/include/chpl/framework/all-global-strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ X(c_ptr , "c_ptr")
X(c_ptrConst , "c_ptrConst")
X(c_char , "c_char")
X(class_ , "class")
X(defaultDist , "defaultDist")
X(deinit , "deinit")
X(deserialize , "deserialize")
X(dmapped , "dmapped")
Expand All @@ -66,6 +67,7 @@ X(index , "index")
X(init , "init")
X(initequals , "init=")
X(int_ , "int")
X(instance_ , "_instance")
X(isCoercible , "isCoercible")
X(leader , "leader")
X(locale , "locale")
Expand Down
28 changes: 21 additions & 7 deletions frontend/include/chpl/parsing/parsing-queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,29 @@ std::string getExistingFileInModuleSearchPath(Context* context,
*/
const uast::Module* getToplevelModule(Context* context, UniqueString name);

struct IdAndName {
ID id;
UniqueString name;
};


/**
Given a particular (presumably standard) module, return the ID of a
symbol with the given name in that module. Beyond creating the ID, this also
ensures that the standard module is parsed, and thus, that 'idToAst' on the
returned ID will return a non-null value.
*/
ID getSymbolIdFromTopLevelModule(Context* context,
const char* modName,
const char* symName);

/**
Given a particular (presumably standard) module, return the ID of a symbol
with the given name in that module. Beyond creating the ID, this also ensures
that the standard module is parsed, and thus, that 'idToAst' on the returned
ID will return a non-null value.
Like getSymbolId..., but return also contains the name of the given symbol for
convenience.
*/
ID getSymbolFromTopLevelModule(Context* context,
const char* modName,
const char* symName);
IdAndName getSymbolFromTopLevelModule(Context* context,
const char* modName,
const char* symName);

/**
This query parses a submodule for 'include submodule'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ERROR_CLASS(IncompatibleKinds, types::QualifiedType::Kind, const uast::AstNode*,
ERROR_CLASS(IncompatibleRangeBounds, const uast::Range*, types::QualifiedType, types::QualifiedType)
ERROR_CLASS(IncompatibleTypeAndInit, const uast::AstNode*, const uast::AstNode*, const uast::AstNode*, const types::Type*, const types::Type*)
ERROR_CLASS(InvalidClassCast, const uast::PrimCall*, types::QualifiedType)
ERROR_CLASS(InvalidDomainCall, const uast::FnCall*, std::vector<types::QualifiedType>)
ERROR_CLASS(InvalidIndexCall, const uast::FnCall*, types::QualifiedType)
ERROR_CLASS(InvalidNewTarget, const uast::New*, types::QualifiedType)
ERROR_CLASS(InvalidParamCast, const uast::AstNode*, types::QualifiedType, types::QualifiedType)
Expand Down
1 change: 1 addition & 0 deletions frontend/include/chpl/resolution/resolution-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,7 @@ class AssociatedAction {
REDUCE_SCAN, // resolution of "generate" for a reduce/scan operation.
INFER_TYPE,
COMPARE, // == , e.g., for select-statements
RUNTIME_TYPE, // create runtime type
};

private:
Expand Down
3 changes: 3 additions & 0 deletions frontend/include/chpl/types/CompositeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ class CompositeType : public Type {
/** Get the chpl_localeID_t type */
static const RecordType* getLocaleIDType(Context* context);

/** Get the _distribution type */
static const RecordType* getDistributionType(Context* context);

/** Get the record _owned implementing owned */
static const RecordType* getOwnedRecordType(Context* context, const BasicClassType* bct);

Expand Down
10 changes: 7 additions & 3 deletions frontend/include/chpl/types/DomainType.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DomainType final : public CompositeType {
// TODO: distributions
Kind kind_;

// Will compute idxType, rank, and stridable from 'subs'
// Will compute idxType, rank, and strides from 'subs'
DomainType(ID id, UniqueString name,
const DomainType* instantiatedFrom,
SubstitutionsMap subs,
Expand Down Expand Up @@ -91,15 +91,19 @@ class DomainType final : public CompositeType {

/** Return a rectangular domain type */
static const DomainType* getRectangularType(Context* context,
const QualifiedType& instance,
const QualifiedType& rank,
const QualifiedType& idxType,
const QualifiedType& stridable);
const QualifiedType& strides);

/** Return an associative domain type */
static const DomainType* getAssociativeType(Context* context,
const QualifiedType& idxType,
const QualifiedType& parSafe);

/** Get the default distribution type */
static const QualifiedType& getDefaultDistType(Context* context);

Kind kind() const {
return kind_;
}
Expand All @@ -123,7 +127,7 @@ class DomainType final : public CompositeType {
}
}

const QualifiedType& stridable() const {
const QualifiedType& strides() const {
CHPL_ASSERT(kind_ == Kind::Rectangular);
return subs_.at(ID(UniqueString(), 2, 0));
}
Expand Down
13 changes: 10 additions & 3 deletions frontend/lib/parsing/parsing-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,9 @@ const Module* getToplevelModule(Context* context, UniqueString name) {
return getToplevelModuleQuery(context, name);
}

ID getSymbolFromTopLevelModule(Context* context,
const char* modName,
const char* symName) {
ID getSymbolIdFromTopLevelModule(Context* context,
const char* modName,
const char* symName) {
std::ignore = getToplevelModule(context, UniqueString::get(context, modName));

// Performance: this has to concatenate the two strings at runtime.
Expand All @@ -1127,6 +1127,13 @@ ID getSymbolFromTopLevelModule(Context* context,
return ID(UniqueString::get(context, fullPath));
}

IdAndName getSymbolFromTopLevelModule(Context* context,
const char* modName,
const char* symName) {
return {getSymbolIdFromTopLevelModule(context, modName, symName),
UniqueString::get(context, symName)};
}

static const Module* const&
getIncludedSubmoduleQuery(Context* context, ID includeModuleId) {
QUERY_BEGIN(getIncludedSubmoduleQuery, context, includeModuleId);
Expand Down
60 changes: 58 additions & 2 deletions frontend/lib/resolution/InitResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,57 @@ bool InitResolver::isFinalReceiverStateValid(void) {
return ret;
}

// Extract domain type information from _instance substitution
static const DomainType* domainTypeFromSubsHelper(
Context* context, const CompositeType::SubstitutionsMap& subs) {
auto genericDomain = DomainType::getGenericDomainType(context);

// Expect one substitution for _instance
if (subs.size() != 1) return genericDomain;

const QualifiedType instanceQt = subs.begin()->second;

if (auto instance = instanceQt.type()) {
if (auto instanceCt = instance->toClassType()) {
if (auto instanceBct = instanceCt->basicClassType()) {
// Get BaseRectangularDom parent subs for rectangular domain info
if (auto baseDom = instanceBct->parentClassType()) {
auto& rf = fieldsForTypeDecl(context, baseDom,
DefaultsPolicy::IGNORE_DEFAULTS);
if (baseDom->id().symbolPath() == "ChapelDistribution.BaseRectangularDom") {
CHPL_ASSERT(rf.numFields() == 3);
QualifiedType rank;
QualifiedType idxType;
QualifiedType strides;
for (int i = 0; i < rf.numFields(); i++) {
if (rf.fieldName(i) == "rank") {
rank = rf.fieldType(i);
} else if (rf.fieldName(i) == "idxType") {
idxType = rf.fieldType(i);
} else if (rf.fieldName(i) == "strides") {
strides = rf.fieldType(i);
}
}

return DomainType::getRectangularType(context, instanceQt, rank,
idxType, strides);
} else if (baseDom->id().symbolPath() == "ChapelDistribution.BaseAssociativeDom") {
// TODO: support associative domains
} else if (baseDom->id().symbolPath() == "ChapelDistribution.BaseSparseDom") {
// TODO: support sparse domains
} else {
// not a recognized domain type
return genericDomain;
}
}
}
}
}

// If we reach here, we weren't able to resolve the domain type
return genericDomain;
}

static const Type* ctFromSubs(Context* context,
const Type* receiverType,
const BasicClassType* superType,
Expand Down Expand Up @@ -313,6 +364,8 @@ static const Type* ctFromSubs(Context* context,
auto manager = AnyOwnedType::get(context);
auto dec = ClassTypeDecorator(ClassTypeDecorator::BORROWED_NONNIL);
ret = ClassType::get(context, basic, manager, dec);
} else if (receiverType->isDomainType()) {
ret = domainTypeFromSubsHelper(context, subs);
} else {
CHPL_ASSERT(false && "Not handled!");
}
Expand Down Expand Up @@ -400,9 +453,12 @@ const Type* InitResolver::computeReceiverTypeConsideringState(void) {
QualifiedType::Kind InitResolver::determineReceiverIntent(void) {
if (initialRecvType_->isClassType()) {
return QualifiedType::CONST_IN;
} else {
CHPL_ASSERT(initialRecvType_->isRecordType());
} else if (initialRecvType_->isRecordType() ||
initialRecvType_->isDomainType()) {
return QualifiedType::REF;
} else {
CHPL_ASSERT(false && "Not handled");
return QualifiedType::UNKNOWN;
}
}

Expand Down
Loading