Skip to content

Commit

Permalink
Merge branch 'main' into fixConstRefModsToo
Browse files Browse the repository at this point in the history
Signed-off-by: Lydia Duncan <[email protected]>
  • Loading branch information
lydia-duncan committed Oct 3, 2024
2 parents 79afb8d + 328bb70 commit 467aff2
Show file tree
Hide file tree
Showing 67 changed files with 2,346 additions and 330 deletions.
7 changes: 7 additions & 0 deletions compiler/passes/convert-uast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4530,6 +4530,11 @@ Type* Converter::helpConvertType(types::QualifiedType qt) {
case typetags::UnknownType: return dtUnknown;
case typetags::VoidType: return dtVoid;

// subclasses of IterableType
case typetags::FnIteratorType: return dtUnknown; // a lie
case typetags::LoopExprIteratorType: return dtUnknown; // a lie
case typetags::PromotionIteratorType: return dtUnknown; // a lie

// subclasses of BuiltinType

// concrete builtin types
Expand Down Expand Up @@ -4592,6 +4597,8 @@ Type* Converter::helpConvertType(types::QualifiedType qt) {
case typetags::END_CompositeType:
case typetags::START_PrimitiveType:
case typetags::END_PrimitiveType:
case typetags::START_IteratorType:
case typetags::END_IteratorType:
case typetags::NUM_TYPE_TAGS:
INT_FATAL("should not be reachable");
return dtUnknown;
Expand Down
41 changes: 41 additions & 0 deletions frontend/include/chpl/framework/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,47 @@ class Context {
#endif
;

/**
Note an warning for the currently running query.
This is a convenience overload.
This version takes in a Location and a printf-style format string.
*/
void warning(Location loc, const char* fmt, ...)
#ifndef DOXYGEN
// docs generator has trouble with the attribute applied to 'build'
// so the above ifndef works around the issue.
__attribute__ ((format (printf, 3, 4)))
#endif
;

/**
Note an warning for the currently running query.
This is a convenience overload.
This version takes in an ID and a printf-style format string.
The ID is used to compute a Location using parsing::locateId.
*/
void warning(ID id, const char* fmt, ...)
#ifndef DOXYGEN
// docs generator has trouble with the attribute applied to 'build'
// so the above ifndef works around the issue.
__attribute__ ((format (printf, 3, 4)))
#endif
;

/**
Note an warning for the currently running query.
This is a convenience overload.
This version takes in an AST node and a printf-style format string.
The AST node is used to compute a Location by using a parsing::locateAst.
*/
void warning(const uast::AstNode* ast, const char* fmt, ...)
#ifndef DOXYGEN
// docs generator has trouble with the attribute applied to 'build'
// so the above ifndef works around the issue.
__attribute__ ((format (printf, 3, 4)))
#endif
;

/**
Sets the enableDebugTrace flag. This was needed because the context
in main gets created before the arguments to the compiler are parsed.
Expand Down
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 @@ -82,6 +82,7 @@ X(none , "none")
X(nothing , "nothing")
X(object_ , "object")
X(owned , "owned")
X(owned_ , "_owned")
X(postinit , "postinit")
X(real_ , "real")
X(reduce , "reduce")
Expand All @@ -90,6 +91,7 @@ X(RootClass , "RootClass")
X(scan , "scan")
X(serialize , "serialize")
X(shared , "shared")
X(shared_ , "_shared")
X(single , "single")
X(size , "size")
X(sparse , "sparse")
Expand Down
7 changes: 7 additions & 0 deletions frontend/include/chpl/resolution/resolution-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,13 @@ class TypedFnSignature {
return fetchIterKindStr(context, str) && str == USTR("follower");
}

/** Returns 'true' if this signature is for a parallel iterator. */
bool isParallelIterator(Context* context) const {
return isParallelStandaloneIterator(context) ||
isParallelLeaderIterator(context) ||
isParallelFollowerIterator(context);
}

/** Returns 'true' if this signature is for a serial iterator. */
bool isSerialIterator(Context* context) const {
UniqueString str;
Expand Down
4 changes: 4 additions & 0 deletions frontend/include/chpl/types/ClassType.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class ClassType final : public Type {
/** Returns the version of this ClassType with the passed decorator */
const ClassType* withDecorator(Context* context,
ClassTypeDecorator decorator) const;

/** Returns the recordType for the manager */
const RecordType* managerRecordType(Context* context) const;

};


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

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

/** Get the record _shared implementing shared */
static const RecordType* getSharedRecordType(Context* context, const BasicClassType* bct);

/** When compiling without a standard library (for testing purposes),
the compiler code needs to work around the fact that there
is no definition available for the bundled types needed
Expand Down
69 changes: 69 additions & 0 deletions frontend/include/chpl/types/FnIteratorType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CHPL_TYPES_FN_ITERATOR_TYPE_H
#define CHPL_TYPES_FN_ITERATOR_TYPE_H

#include "chpl/types/Type.h"
#include "chpl/types/QualifiedType.h"
#include "chpl/resolution/resolution-types.h"
#include "chpl/types/IteratorType.h"

namespace chpl {
namespace types {

class FnIteratorType final : public IteratorType {
private:
/*
The iterator procedure that was invoked to construct an iterator of this
type. E.g,, the type of `foo()` will contain `iter foo()` as the iterator
function.
*/
const resolution::TypedFnSignature* iteratorFn_;

FnIteratorType(QualifiedType yieldType, const resolution::TypedFnSignature* iteratorFn)
: IteratorType(typetags::FnIteratorType, std::move(yieldType)), iteratorFn_(iteratorFn) {}

bool contentsMatchInner(const Type* other) const override {
auto rhs = (FnIteratorType*) other;
return this->yieldType_ == rhs->yieldType_ &&
this->iteratorFn_ == rhs->iteratorFn_;
}

void markUniqueStringsInner(Context* context) const override;

static const owned <FnIteratorType>&
getFnIteratorType(Context* context,
QualifiedType yieldType,
const resolution::TypedFnSignature* iteratorFn);

public:
static const FnIteratorType* get(Context* context,
QualifiedType yieldType,
const resolution::TypedFnSignature* iteratorFn);

const resolution::TypedFnSignature* iteratorFn() const {
return iteratorFn_;
}
};

} // end namespace types
} // end namespace chpl

#endif
57 changes: 57 additions & 0 deletions frontend/include/chpl/types/IteratorType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CHPL_TYPES_ITERATOR_TYPE_H
#define CHPL_TYPES_ITERATOR_TYPE_H

#include "chpl/types/Type.h"
#include "chpl/types/QualifiedType.h"

namespace chpl {
namespace types {

class IteratorType : public Type {
protected:
/*
The type produced by this iterator. E.g., in a loop such
as the right hand side in the below assignment:
var A = foreach i in 1..10 do (i,i);
the yield type is (int, int).
*/
QualifiedType yieldType_;

IteratorType(typetags::TypeTag tag, QualifiedType yieldType)
: Type(tag), yieldType_(std::move(yieldType)) {}

Genericity genericity() const override {
return CONCRETE;
}

public:
const QualifiedType& yieldType() const {
return yieldType_;
}
};

} // end namespace types
} // end namespace chpl

#endif
124 changes: 124 additions & 0 deletions frontend/include/chpl/types/LoopExprIteratorType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright 2024 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CHPL_TYPES_LOOP_EXPR_ITERATOR_TYPE_H
#define CHPL_TYPES_LOOP_EXPR_ITERATOR_TYPE_H

#include "chpl/types/Type.h"
#include "chpl/types/QualifiedType.h"
#include "chpl/types/IteratorType.h"

namespace chpl {
namespace types {

class LoopExprIteratorType final : public IteratorType {
private:
/*
Whether the loop expression is zippered. In production, zippered
loop expressions contain all of their iterands and separately invoke
leader/follower iterators on each one
*/
bool isZippered_;
/*
Whether this loop can be iterated over in parallel. Some loops
('for' and 'foreach') can't, even when their iterands support parallel
iteration.
*/
bool supportsParallel_;
/*
The type of the thing being iterated over, used for resolving the
needed leader/follower iterators. If the loop is zippered, iterand
should be a tuple type.
*/
QualifiedType iterand_;
/*
The ID of the AST node that caused this loop type to be constructed.
This is part of the type so that loop expressions created at different
places are considered to have a different type.
Note: this may need to change if we compiler-generated loop expressions,
since the IDs of those would be nebulous.
*/
ID sourceLocation_;

LoopExprIteratorType(QualifiedType yieldType,
bool isZippered,
bool supportsParallel,
QualifiedType iterand,
ID sourceLocation)
: IteratorType(typetags::LoopExprIteratorType, std::move(yieldType)),
isZippered_(isZippered), supportsParallel_(supportsParallel),
iterand_(std::move(iterand)), sourceLocation_(std::move(sourceLocation)) {
if (isZippered_) {
CHPL_ASSERT(iterand_.type() && iterand_.type()->isTupleType());
}
}

bool contentsMatchInner(const Type* other) const override {
auto rhs = (LoopExprIteratorType*) other;
return yieldType_ == rhs->yieldType_ &&
isZippered_ == rhs->isZippered_ &&
supportsParallel_ == rhs->supportsParallel_ &&
iterand_ == rhs->iterand_ &&
sourceLocation_ == rhs->sourceLocation_;
}

void markUniqueStringsInner(Context* context) const override {
yieldType_.mark(context);
iterand_.mark(context);
sourceLocation_.mark(context);
}

static const owned<LoopExprIteratorType>&
getLoopExprIteratorType(Context* context,
QualifiedType yieldType,
bool isZippered,
bool supportsParallel,
QualifiedType iterand,
ID sourceLocation);

public:
static const LoopExprIteratorType* get(Context* context,
QualifiedType yieldType,
bool isZippered,
bool supportsParallel,
QualifiedType iterand,
ID sourceLocation);

bool isZippered() const {
return isZippered_;
}

bool supportsParallel() const {
return supportsParallel_;
}

const ID& sourceLocation() const {
return sourceLocation_;
}

const QualifiedType& iterand() const {
return iterand_;
}
};

} // end namespace types
} // end namespace chpl

#endif
Loading

0 comments on commit 467aff2

Please sign in to comment.