diff options
| author | Theresa Foley <10618364+tangent-vector@users.noreply.github.com> | 2025-10-02 21:48:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-03 04:48:11 +0000 |
| commit | cc8f6a241edb47c43c5698ee33abed4fe57d4566 (patch) | |
| tree | d40789640b6b5901c305332ded7f751e48037e93 /source/slang/slang-check-decl.cpp | |
| parent | 0c778339d7e3c39f600af2cc049f13f661d3434b (diff) | |
Rename some symbols related to pointers types (#8592)
Note that while this change touched a large numer of files, there are no
changes to functionality being made here. The only things being done are
renaming various symbols and, in a few cases, updating or adding
comments for consistency with the new names.
The core of the naming changes are:
* Most things named to refer to `OutType` (e.g., `IROutType`,
`IRBuilder::getOutType()`, etc.) have been consistently renamed to refer
to `OutParamType`, to emphasize that the relevant AST/IR node types are
only intended for use to represent `out` parameters.
* The same change as described above for `OutType` is also made for
`RefType`, which becomes `RefParamType` in most cases. One mess that
this exposes is the way that the `ExplicitRef<T>` type in the core
module currently lowers to `IRRefParamType`. This change sticks to the
rule of not making functional changes, so that mess is left as-is for
now.
* Names referring to `InOutType` have been changed to instead refer to
`BorrowInOutType`. The intention with this naming change is to emphasize
that the Slang rules for `inout` are semantically those of a borrow (or
at least our interpretation of what a borrow means).
* Names referring to `ConstRefType` have been changed to instead refer
to `BorrowInType`. This change starts work on clarifying that the
existing `__constref` modifier was never intended to be a read-only
analogue of `__ref`, and instead is the input-only analogue of `inout`.
* The `ParameterDirection` enum type has been changed to
`ParamPassingMode`, to reflect the fact that the concept of "direction"
fails to capture what is actually being encoded, particularly once we
have modes beyond simple `in`/`out`/`inout`.
While this change does not alter behavior in any case (the user-exposed
Slang language is unchanged), it is intended to set up subsequence
changes that will work to make the handling of these types in the
compiler more nuanced and correct. Breaking this part of the change out
separately is primarily motivated by a desire to minimize the effort for
reviewers.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 2afd05df2..6a4e3668f 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -5202,13 +5202,13 @@ void SemanticsVisitor::addRequiredParamsToSynthesizedDecl( } else if ( as<InOutModifier>(modifier) || as<OutModifier>(modifier) || - as<ConstRefModifier>(modifier) || as<RefModifier>(modifier)) + as<BorrowModifier>(modifier) || as<RefModifier>(modifier)) { auto clonedModifier = (Modifier*)m_astBuilder->createByNodeType(modifier->astNodeType); clonedModifier->keywordName = modifier->keywordName; addModifier(synParamDecl, clonedModifier); - if (as<ConstRefModifier>(modifier)) + if (as<BorrowModifier>(modifier)) paramType.isLeftValue = false; } } @@ -5361,15 +5361,15 @@ static bool isWrapperTypeDecl(Decl* decl) // Is it allowed to have an interface method parameter whose direction is `reqDir`, and an // implementing method parameter whose direction is `implDir`? // -static bool matchParamDirection(ParameterDirection implDir, ParameterDirection reqDir) +static bool matchParamDirection(ParamPassingMode implDir, ParamPassingMode reqDir) { // If the parameter directions match exactly, then we are good. if (implDir == reqDir) return true; // Otherwise, we only allow the cases where reqDir is `InOut` and implDir is `In` or `Out`. - if (implDir == kParameterDirection_In && reqDir == kParameterDirection_InOut) + if (implDir == ParamPassingMode::In && reqDir == ParamPassingMode::BorrowInOut) return true; - if (implDir == kParameterDirection_Out && reqDir == kParameterDirection_InOut) + if (implDir == ParamPassingMode::Out && reqDir == ParamPassingMode::BorrowInOut) return true; return false; } @@ -9440,8 +9440,8 @@ bool SemanticsVisitor::doFunctionSignaturesMatch(DeclRef<FuncDecl> fst, DeclRef< // If one parameter is `constref` and the other isn't, then they don't match. // - if (fstParam.getDecl()->hasModifier<ConstRefModifier>() != - sndParam.getDecl()->hasModifier<ConstRefModifier>()) + if (fstParam.getDecl()->hasModifier<BorrowModifier>() != + sndParam.getDecl()->hasModifier<BorrowModifier>()) return false; } @@ -9962,7 +9962,7 @@ void SemanticsDeclHeaderVisitor::visitParamDecl(ParamDecl* paramDecl) isMutable = true; continue; } - if (as<RefModifier>(modifier) || as<ConstRefModifier>(modifier)) + if (as<RefModifier>(modifier) || as<BorrowModifier>(modifier)) { hasRefModifier = true; } @@ -9973,7 +9973,7 @@ void SemanticsDeclHeaderVisitor::visitParamDecl(ParamDecl* paramDecl) if (isMutable) newModifiers.add(this->getASTBuilder()->create<RefModifier>()); else - newModifiers.add(this->getASTBuilder()->create<ConstRefModifier>()); + newModifiers.add(this->getASTBuilder()->create<BorrowModifier>()); } paramDecl->modifiers.first = newModifiers.getFirst(); for (Index i = 0; i < newModifiers.getCount(); i++) @@ -9992,7 +9992,7 @@ void SemanticsDeclHeaderVisitor::visitParamDecl(ParamDecl* paramDecl) for (auto modifier : paramDecl->modifiers) { if (as<OutModifier>(modifier) || as<InOutModifier>(modifier) || - as<RefModifier>(modifier) || as<ConstRefModifier>(modifier)) + as<RefModifier>(modifier) || as<BorrowModifier>(modifier)) { getSink()->diagnose(modifier, Diagnostics::parameterPackMustBeConst); } @@ -10534,17 +10534,17 @@ void SemanticsDeclHeaderVisitor::setFuncTypeIntoRequirementDecl( param->type.type = paramType; switch (paramDir) { - case ParameterDirection::kParameterDirection_InOut: + case ParamPassingMode::BorrowInOut: addModifier(param, m_astBuilder->create<InOutModifier>()); break; - case ParameterDirection::kParameterDirection_Out: + case ParamPassingMode::Out: addModifier(param, m_astBuilder->create<OutModifier>()); break; - case ParameterDirection::kParameterDirection_Ref: + case ParamPassingMode::Ref: addModifier(param, m_astBuilder->create<RefModifier>()); break; - case ParameterDirection::kParameterDirection_ConstRef: - addModifier(param, m_astBuilder->create<ConstRefModifier>()); + case ParamPassingMode::BorrowIn: + addModifier(param, m_astBuilder->create<BorrowModifier>()); break; default: break; @@ -10657,11 +10657,11 @@ void SemanticsDeclHeaderVisitor::checkDifferentiableCallableCommon(CallableDecl* } if (!paramDecl->hasModifier<NoDiffModifier>()) { - if (auto modifier = paramDecl->findModifier<ConstRefModifier>()) + if (auto modifier = paramDecl->findModifier<BorrowModifier>()) { getSink()->diagnose( modifier, - Diagnostics::cannotUseConstRefOnDifferentiableParameter); + Diagnostics::cannotUseBorrowInOnDifferentiableParameter); } } } @@ -12946,10 +12946,10 @@ Type* getTypeForThisExpr(SemanticsVisitor* visitor, DeclRef<FunctionDeclBase> fu struct ArgsWithDirectionInfo { List<Expr*> args; - List<ParameterDirection> directions; + List<ParamPassingMode> directions; Expr* thisArg; - ParameterDirection thisArgDirection; + ParamPassingMode thisArgDirection; }; template<typename TDerivativeAttr> @@ -12958,9 +12958,9 @@ void checkDerivativeAttributeImpl( Decl* funcDecl, TDerivativeAttr* attr, const List<Expr*>& imaginaryArguments, - const List<ParameterDirection>& expectedParamDirections, + const List<ParamPassingMode>& expectedParamDirections, Expr* expectedThisArg, - ParameterDirection expectedThisArgDirection) + ParamPassingMode expectedThisArgDirection) { if (isInterfaceRequirement(funcDecl)) { @@ -13055,20 +13055,20 @@ void checkDerivativeAttributeImpl( } // If left value is true, then convert the - // inner type to an InOutType. + // inner type to an BorrowInOutParamType. // auto qualTypeToString = [&](QualType qualType) -> String { Type* type = qualType.type; if (qualType.isLeftValue) { - type = ctx.getASTBuilder()->getInOutType(type); + type = ctx.getASTBuilder()->getBorrowInOutParamType(type); } return type->toString(); }; List<Expr*> argList = imaginaryArguments; - List<ParameterDirection> paramDirections = expectedParamDirections; + List<ParamPassingMode> paramDirections = expectedParamDirections; bool expectStaticFunc = false; if (expectedThisArg) @@ -13275,7 +13275,7 @@ ArgsWithDirectionInfo getImaginaryArgsToFunc( SourceLoc loc) { List<Expr*> imaginaryArguments; - List<ParameterDirection> directions; + List<ParamPassingMode> directions; for (auto param : func->getParameters()) { auto arg = astBuilder->create<VarExpr>(); @@ -13286,7 +13286,7 @@ ArgsWithDirectionInfo getImaginaryArgsToFunc( imaginaryArguments.add(arg); directions.add(getParameterDirection(param)); } - return {imaginaryArguments, directions, nullptr, ParameterDirection::kParameterDirection_In}; + return {imaginaryArguments, directions, nullptr, ParamPassingMode::In}; } ArgsWithDirectionInfo getImaginaryArgsToForwardDerivative( @@ -13314,9 +13314,9 @@ ArgsWithDirectionInfo getImaginaryArgsToForwardDerivative( } } - ParameterDirection thisTypeDirection = (thisArgExpr && !thisArgExpr->type.isLeftValue) - ? ParameterDirection::kParameterDirection_In - : ParameterDirection::kParameterDirection_InOut; + ParamPassingMode thisTypeDirection = (thisArgExpr && !thisArgExpr->type.isLeftValue) + ? ParamPassingMode::In + : ParamPassingMode::BorrowInOut; List<Expr*> imaginaryArguments; for (auto param : originalFuncDecl->getParameters()) @@ -13337,7 +13337,7 @@ ArgsWithDirectionInfo getImaginaryArgsToForwardDerivative( } // Copy parameter directions as is. - List<ParameterDirection> expectedParamDirections; + List<ParamPassingMode> expectedParamDirections; for (auto param : originalFuncDecl->getParameters()) { expectedParamDirections.add(getParameterDirection(param)); @@ -13375,12 +13375,12 @@ ArgsWithDirectionInfo getImaginaryArgsToBackwardDerivative( } } - ParameterDirection thisTypeDirection = (thisArgExpr && !thisArgExpr->type.isLeftValue) - ? ParameterDirection::kParameterDirection_In - : ParameterDirection::kParameterDirection_InOut; + ParamPassingMode thisTypeDirection = (thisArgExpr && !thisArgExpr->type.isLeftValue) + ? ParamPassingMode::In + : ParamPassingMode::BorrowInOut; List<Expr*> imaginaryArguments; - List<ParameterDirection> expectedParamDirections; + List<ParamPassingMode> expectedParamDirections; auto isOutParam = [&](ParamDecl* param) { @@ -13397,7 +13397,7 @@ ArgsWithDirectionInfo getImaginaryArgsToBackwardDerivative( arg->type.type = param->getType(); arg->loc = loc; - ParameterDirection direction = getParameterDirection(param); + ParamPassingMode direction = getParameterDirection(param); bool isDiffParam = (!param->findModifier<NoDiffModifier>()); if (isDiffParam) @@ -13416,13 +13416,13 @@ ArgsWithDirectionInfo getImaginaryArgsToBackwardDerivative( visitor->getASTBuilder(), pairType->getPrimalType()); - direction = ParameterDirection::kParameterDirection_In; + direction = ParamPassingMode::In; } else { // in T : IDifferentiable -> inout DifferentialPair<T> // inout T : IDifferentiable -> inout DifferentialPair<T> - direction = ParameterDirection::kParameterDirection_InOut; + direction = ParamPassingMode::BorrowInOut; } } else if (auto refPairType = as<DifferentialPtrPairType>(diffPair)) @@ -13446,7 +13446,7 @@ ArgsWithDirectionInfo getImaginaryArgsToBackwardDerivative( // no_diff inout T -> in T // no_diff in T -> in T // - direction = ParameterDirection::kParameterDirection_In; + direction = ParamPassingMode::In; } imaginaryArguments.add(arg); @@ -13461,7 +13461,7 @@ ArgsWithDirectionInfo getImaginaryArgsToBackwardDerivative( arg->type.type = diffReturnType; arg->loc = loc; imaginaryArguments.add(arg); - expectedParamDirections.add(ParameterDirection::kParameterDirection_In); + expectedParamDirections.add(ParamPassingMode::In); } return {imaginaryArguments, expectedParamDirections, thisArgExpr, thisTypeDirection}; |
