sun::semantic_analysis
namespace · Source (opens in a new tab)
Resolves declarations and checks the types and meaning of Sun programs.
Compares the semantic inputs to nominal specializations.
Prepares generic deduction inputs and reports contextual failures.
Resolves names, members, and the semantic facts needed by inference.
Implements storage and control-flow queries on analyzed expressions.
Resolves calls using the active semantic session.
Coordinates dispatch to declaration, statement, and expression checking.
Defines declaration identity shared by class, interface, and enum types.
Owns nominal type registration and specialization identities for a session.
Resolves names and types and checks program semantics.
Resolves class shapes and concrete signatures after type registration.
Resolves declarations and checks the meaning of Sun programs.
Turns inference failures into source-located semantic diagnostics.
Prepares generic parameter shapes for sun::semantic_analysis::type_analysis and reports deduction failures using the call's source location and display name.
Queries storage and control-flow properties of analyzed expressions.
Checks a declaration on its own, without looking anything up in scope.
Provides focused checking services for one semantic analysis session.
Resolves declarations and checks the types and meaning of Sun programs.
Checks expression properties during semantic analysis.
Specialization remains the caller's responsibility. Resolves declarations and checks the types and meaning of Sun programs.
Diagnostic adapters used by semantic analysis.
Declaration identities, qualified names, module scopes, nominal types, and generic templates must already be registered before this pass runs. Resolves declarations and checks the types and meaning of Sun programs.
Registers declarations and their nominal types during semantic analysis.
Owns registration of nominal types during semantic analysis.
Semantic adapters for generic argument deduction.
Namespaces
- sun::semantic_analysis::constants
- sun::semantic_analysis::type_analysis
- sun::semantic_analysis::passes
Classes
- sun::semantic_analysis::BodyAnalyzer (public)
- sun::semantic_analysis::CallAnalyzer (public)
- sun::semantic_analysis::MethodSignatureSet (public)
- sun::semantic_analysis::ClassAnalyzer (public)
- sun::semantic_analysis::DeclarationAnalyzer (public)
- sun::semantic_analysis::DeclarationId (public)
- sun::semantic_analysis::DeclarationState (public)
- sun::semantic_analysis::DeclarationTable (public)
- sun::semantic_analysis::EnumAnalyzer (public)
- sun::semantic_analysis::ExpressionAnalyzer (public)
- sun::semantic_analysis::GenericSpecializer (public)
- sun::semantic_analysis::InterfaceAnalyzer (public)
- sun::semantic_analysis::PortableTypeKey (public)
- sun::semantic_analysis::PortableDeclarationKey (public)
- sun::semantic_analysis::SemanticAnalyzer (public)
- sun::semantic_analysis::SemanticContext (public)
- sun::semantic_analysis::SemanticPipeline (public)
- sun::semantic_analysis::FunctionTable (public)
- sun::semantic_analysis::AccessFilter (public)
- sun::semantic_analysis::TypeRegistry (public)
Structs
- sun::semantic_analysis::ItemRef (public)
- sun::semantic_analysis::AnalysisResults (public)
- sun::semantic_analysis::CallableSignature (public)
- sun::semantic_analysis::CallableSignatureHash (public)
- sun::semantic_analysis::LibraryDeclarationIdentity (public)
- sun::semantic_analysis::LibraryDeclarationRecord (public)
- sun::semantic_analysis::DeclarationIdentity (public)
- sun::semantic_analysis::DeclarationRecord (public)
- sun::semantic_analysis::IsGuard (public)
- sun::semantic_analysis::QualifiedName (public)
- sun::semantic_analysis::FunctionArgumentType (public)
- sun::semantic_analysis::VariableInfo (public)
- sun::semantic_analysis::UnanalyzedGlobal (public)
- sun::semantic_analysis::FunctionInfo (public)
- sun::semantic_analysis::UsingImport (public)
- sun::semantic_analysis::ImportBinding (public)
- sun::semantic_analysis::SymbolMatch (public)
- sun::semantic_analysis::GenericClassInfo (public)
- sun::semantic_analysis::GenericInterfaceInfo (public)
- sun::semantic_analysis::GenericEnumInfo (public)
- sun::semantic_analysis::GenericFunctionInfo (public)
- sun::semantic_analysis::SpecializedFunctionInfo (public)
- sun::semantic_analysis::AccessContext (public)
- sun::semantic_analysis::SemanticScopeBase (public)
- sun::semantic_analysis::GlobalScope (public)
- sun::semantic_analysis::ModuleScope (public)
- sun::semantic_analysis::ImportScope (public)
- sun::semantic_analysis::FunctionScope (public)
- sun::semantic_analysis::ClassScope (public)
- sun::semantic_analysis::InterfaceScope (public)
- sun::semantic_analysis::BlockScope (public)
- sun::semantic_analysis::TypeParamsScope (public)
- sun::semantic_analysis::StructInfo (public)
- sun::semantic_analysis::SpecializationKey (public)
- sun::semantic_analysis::SpecializationKeyHash (public)
Functions
- accessItem
- accessedClass
- alwaysExits
- anyMentionsTypeParameter
- borrowRejection
- checkAllPathsReturn
- checkCharOperands
- checkConstructorStatus
- checkFieldInitialization
- checkOwnedMatchArmTypes
- checkOwnedMatchCoverage
- checkPackedFieldNotBorrowed
- checkPackedFieldType
- checkPackedRefArguments
- checkResultHandling
- classifyArgument
- classifyArguments
- coerceBinaryLiteralOperands
- collectAllModuleScopes
- completeTestReturns
- constructorResult
- containsCall
- denialMessage
- denyAccess
- describeOwner
- displayModulePath
- fieldAlign
- fieldPhrase
- fieldRef
- findThisUse
- findVariableNode
- forEachGlobalDeclaration
- formatFunctionSignature
- formatTypeList
- isAccessible
- isAssignableTo
- isBorrowableLvalue
- isFieldAccess
- isImportScope
- isIntrinsic
- isLibraryHashSegment
- isLibraryScope
- isReservedIdentifier
- libraryHashOf
- logAndThrowError
- lvalueAlign
- matchIsGuard
- mentionsTypeParameter
- methodRef
- methodVisibility
- moduleRef
- prepareFieldInitializers
- preparedBlockType
- preparedMatchType
- reachableMatchArms
- rejectDuplicateLifetimes
- rejectFieldType
- rejectPartialMove
- rejectRefEnvReturnType
- requireAccessible
- requireArguments
- requireInferredType
- requireResolvedType
- resolveGenericTypeArguments
- resolveMethodTypeArguments
- sameTypeArguments
- shadowsGlobalVariable
- splitModulePath
- splitPackArgTypes
- toString
- tryCoerceIntegerLiteral
- typeMovesOnRead
- typeNeedsDrop
- unifyTernaryTypes
- unwrapRef
- validateExternSignature
- validateFieldNames
- validateNotReserved
- visibilityKeyword
- visibleModulePath
accessItem
accessItem(const VariableInfo *v)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const VariableInfo *v)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, VariableInfo
accessItem(const GenericClassInfo *g)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const GenericClassInfo *g)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, GenericClassInfo
accessItem(const std::shared_ptr< sun::types::EnumType > &e)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const std::shared_ptr< sun::types::EnumType > &e)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, sun::types::EnumType
accessItem(const FunctionInfo *f)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const FunctionInfo *f)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, FunctionInfo
accessItem(const std::shared_ptr< sun::types::InterfaceType > &i)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const std::shared_ptr< sun::types::InterfaceType > &i)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, sun::types::InterfaceType
accessItem(const ModuleScope &m)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const ModuleScope &m)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, ModuleScope
accessItem(const std::shared_ptr< sun::types::ClassType > &c)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const std::shared_ptr< sun::types::ClassType > &c)accessItem — describe a lookup result for the access predicate
Visibility comes from the record (or its AST for generic templates); the declaration ID selects the owning module from the declaration table.
Related: sun::semantic_analysis::ItemRef, sun::types::ClassType, Visibility
accessItem(const FunctionInfo &f)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const FunctionInfo &f)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, FunctionInfo
accessItem(const GenericInterfaceInfo *g)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const GenericInterfaceInfo *g)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, GenericInterfaceInfo
accessItem(const GenericEnumInfo *g)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const GenericEnumInfo *g)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, GenericEnumInfo
accessItem(const GenericFunctionInfo *g)
public · function · Source (opens in a new tab)
sun::semantic_analysis::ItemRef sun::semantic_analysis::accessItem(const GenericFunctionInfo *g)Wraps a declaration in the common representation used for visibility checks.
Related: sun::semantic_analysis::ItemRef, GenericFunctionInfo
accessedClass
public · function · Source (opens in a new tab)
const sun::types::ClassType * sun::semantic_analysis::accessedClass(const ExprAST &object)The class a member access reads through, seeing past ref/raw_ptr/static_ptr.
Returns nullptr when the object is not class-shaped.
Related: sun::types::ClassType, ExprAST
alwaysExits
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::alwaysExits(const ExprAST &expr)Does evaluating this statement guarantee the function exits — through a return or a throw — rather than falling through to whatever comes next?
Reports whether an expression always leaves the current control-flow path.
Conservative: anything unrecognized answers no. Two rules build on it: a non-void body must end on a path where this answers yes (Sun has no implicit returns), and a block whose body always exits produces no value and cannot be bound.
Related: ExprAST
borrowRejection
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::borrowRejection(const std::string &what, const char *remedy)Shared explanation for the ways a packed field's address can escape.
what completes "Cannot <what> - packed fields ...".
checkAllPathsReturn
public · function · static · Source (opens in a new tab)
static void sun::semantic_analysis::checkAllPathsReturn(const PrototypeAST &proto, const BlockExprAST &body, const TypePtr &returnType, const sun::support::Position &loc)Sun has no implicit returns: a function whose signature promises a value must leave through an explicit return on every path.
Checked after the body is analyzed, so match discriminants carry their types.
Related: PrototypeAST, BlockExprAST, TypePtr, sun::support::Position
checkConstructorStatus
public · function · static · Source (opens in a new tab)
static void sun::semantic_analysis::checkConstructorStatus(const TypePtr &type, const sun::support::Position &location)Checks the status enum used by a fallible constructor.
Related: TypePtr, sun::support::Position
checkFieldInitialization
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkFieldInitialization(const sun::ast::FunctionAST &constructor, const sun::types::ClassType &classType, const std::vector< sun::ast::ClassMethodDecl > &methods)Checks a constructor against Sun's two-phase rule, and decides what each write to a field does to the value that was there.
Checks that constructors initialize fields before they are read.
The first phase runs until every field has been assigned. The body may assign fields, and it may call the object's own methods — the walk follows the call into the method's body with the state at that point, so a method may only read fields that already have a value, and what it assigns counts towards the constructor's own obligation. A method's write always replaces and drops, whoever calls it; before a field's first value the storage is all zero, which an owning deinit treats as nothing to release. Reading an unassigned field, or handing this to anything else, is rejected: the object is not a whole value yet. The second phase begins once every field has a value, and behaves like any other method body.
A constructor that can reach its end, or a return, with a field still unassigned is rejected. That field would silently be zero — the same reason a struct literal has to name every field. A write to an owning field that only some paths have assigned is rejected too: it could neither start the field's life nor drop what it replaces.
Along the way each write is tagged: a write that starts a field's life drops nothing, and every other write drops what it replaces. Nothing is decided at run time.
Related: sun::ast::FunctionAST, sun::types::ClassType, sun::ast::ClassMethodDecl
checkOwnedMatchArmTypes
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkOwnedMatchArmTypes(const sun::ast::MatchExprAST &match)When a match produces an owned value, throws unless every reachable arm that yields a value yields exactly that type.
Compares each value-producing reachable arm with the match's type.
Related: sun::ast::MatchExprAST
checkOwnedMatchCoverage
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkOwnedMatchCoverage(const sun::ast::MatchExprAST &match, const sun::types::TypePtr &discriminantType)When a match over a non-enum value produces an owned value, throws unless every input is covered: by a _ arm, or by true and false arms when discriminantType is bool.
Accepts a wildcard arm, or both boolean literals over a bool.
Related: sun::ast::MatchExprAST, sun::types::TypePtr
checkPackedFieldNotBorrowed
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkPackedFieldNotBorrowed(const ExprAST &target, const sun::support::Position &loc)Throws if target is a field reached through a packed class: a packed field has no guaranteed alignment, so it cannot be borrowed.
Related: ExprAST, sun::support::Position
checkPackedFieldType
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkPackedFieldType(const sun::ast::ClassDefinitionAST &classDef, const sun::ast::ClassFieldDecl &field, const sun::types::TypePtr &fieldType)Throws if a packed class declares a field type it cannot lay out.
Related: sun::ast::ClassDefinitionAST, sun::ast::ClassFieldDecl, sun::types::TypePtr
checkPackedRefArguments
checkPackedRefArguments(const std::vector< std::unique_ptr< ExprAST > > &args, const std::vector< sun::types::TypePtr > ¶mTypes)
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkPackedRefArguments(const std::vector< std::unique_ptr< ExprAST > > &args, const std::vector< sun::types::TypePtr > ¶mTypes)The same rule for an argument passed to a ref T parameter.
Related: ExprAST, sun::types::TypePtr
checkPackedRefArguments(const std::vector< std::unique_ptr< sun::ast::ExprAST > > &args, const std::vector< sun::types::TypePtr > ¶mTypes)
public · function · Source (opens in a new tab)
void sun::semantic_analysis::checkPackedRefArguments(const std::vector< std::unique_ptr< sun::ast::ExprAST > > &args, const std::vector< sun::types::TypePtr > ¶mTypes)No documentation comment.
Related: sun::ast::ExprAST, sun::types::TypePtr
checkResultHandling
public · function · static · Source (opens in a new tab)
static void sun::semantic_analysis::checkResultHandling(const BlockExprAST &body, SemanticContext &ctx)Rejects discarded results and result locals that are never used.
Related: BlockExprAST, SemanticContext
classifyArgument
public · function · Source (opens in a new tab)
std::optional< ArgConversion > sun::semantic_analysis::classifyArgument(const sun::types::TypePtr &argType, const sun::types::TypePtr ¶mType, bool cVariadicTail)The conversion that hands an argument of argType to a parameter of paramType.
Chooses the conversion needed to pass one argument to a parameter.
paramType is null past the declared parameters: a C ... tail when cVariadicTail, otherwise a variadic pack. Returns nullopt when no lowering exists — acceptance is checked before this (overload resolution, isAssignableTo), so a nullopt for an accepted pair means the acceptance rules and the lowering rules have drifted apart.
Related: ArgConversion, sun::types::TypePtr
classifyArguments
classifyArguments(const std::vector< TypePtr > &argTypes, const std::vector< TypePtr > ¶mTypes, bool cVariadic, const std::string &calleeName, std::optional< sun::support::Position > loc)
public · function · Source (opens in a new tab)
std::vector< ArgConversion > sun::semantic_analysis::classifyArguments(const std::vector< TypePtr > &argTypes, const std::vector< TypePtr > ¶mTypes, bool cVariadic, const std::string &calleeName, std::optional< sun::support::Position > loc)Checks argument types and records the conversions required by a call.
Related: ArgConversion, TypePtr, sun::support::Position
classifyArguments(const std::vector< sun::types::TypePtr > &argTypes, const std::vector< sun::types::TypePtr > ¶mTypes, bool cVariadic, const std::string &calleeName, std::optional< sun::support::Position > loc)
public · function · Source (opens in a new tab)
std::vector< ArgConversion > sun::semantic_analysis::classifyArguments(const std::vector< sun::types::TypePtr > &argTypes, const std::vector< sun::types::TypePtr > ¶mTypes, bool cVariadic, const std::string &calleeName, std::optional< sun::support::Position > loc)classifyArgument for every argument of a call, in order.
Throws the compile error for a pair with no lowering.
Related: ArgConversion, sun::types::TypePtr, sun::support::Position
collectAllModuleScopes
collectAllModuleScopes(const SemanticScopeBase *startScope, const std::string &dotPath)
public · function · static · Source (opens in a new tab)
static std::vector< SemanticScopeBase * > sun::semantic_analysis::collectAllModuleScopes(const SemanticScopeBase *startScope, const std::string &dotPath)Helper: collect ALL module scopes matching a path across import scopes.
Related: SemanticScopeBase
collectAllModuleScopes(const SemanticScope *startScope, const std::string &dotPath)
public · function · static · Source (opens in a new tab)
static std::vector< SemanticScope * > sun::semantic_analysis::collectAllModuleScopes(const SemanticScope *startScope, const std::string &dotPath)Helper: collect ALL module scopes matching a path across import scopes and using statements.
This handles the case where two .sun imports define the same module name, or where a module is brought in via using. Also collects parent module scopes (e.g., for path "A.B", also collects "A").
Related: SemanticScope
completeTestReturns
public · function · static · Source (opens in a new tab)
static void sun::semantic_analysis::completeTestReturns(sun::ast::ExprAST &expression, const std::string &successVariant)Turns a test's bare success returns into unit result values.
Related: sun::ast::ExprAST
constructorResult
public · function · static · Source (opens in a new tab)
static TypePtr sun::semantic_analysis::constructorResult(GenericSpecializer &generics, const std::shared_ptr< sun::types::EnumType > &status, const TypePtr &object, std::optional< Position > location)Replaces the unit success type with the constructed object, preserving errors.
Related: TypePtr, GenericSpecializer, sun::types::EnumType, Position
containsCall
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::containsCall(const ExprAST &expr)Does this expression, or anything nested inside it, call a function?
Reports whether an expression contains a plain or generic call.
Counts plain calls (half(8)) and generic calls (make<i32>()), and looks into every child, including struct literal values, slice bounds and match patterns.
Related: ExprAST
denialMessage
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::denialMessage(const ItemRef &item, const DeclarationTable &table)Explain why a declaration is inaccessible.
Builds a diagnostic explaining why a declaration cannot be accessed.
Related: ItemRef, DeclarationTable
denyAccess
public · function · Source (opens in a new tab)
void sun::semantic_analysis::denyAccess(const ItemRef &item, const sun::support::Position &loc, const DeclarationTable &table)Report an inaccessible declaration at its use site.
Reports why the current scope cannot access the supplied declaration.
Related: ItemRef, sun::support::Position, DeclarationTable
describeOwner
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::describeOwner(const ItemRef &item, const DeclarationTable &table)Describe the declaring module and enclosing type for diagnostics.
Describes the scope owning an inaccessible declaration.
Related: ItemRef, DeclarationTable
displayModulePath
displayModulePath(const ModulePath &path)
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::displayModulePath(const ModulePath &path)"a.b.c" — drops $hash$ segments; "" for the root.
Related: ModulePath
displayModulePath(const std::string &dotted)
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::displayModulePath(const std::string &dotted)The dotted path as source code spells it: "$hash$.std.io" reads "std.io".
Diagnostics use this so a library's bundle hash never reaches the user.
fieldAlign
public · function · Source (opens in a new tab)
llvm::Align sun::semantic_analysis::fieldAlign(const sun::types::ClassType *owner, llvm::Type *fieldTy, const llvm::DataLayout &DL)Alignment for accessing a field of owner.
Related: sun::types::ClassType
fieldPhrase
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::fieldPhrase(const std::string &ownerName)Formats the owning type name for a field-layout diagnostic.
fieldRef
fieldRef(const sun::types::ClassType &cls, const sun::types::ClassField &f)
public · function · Source (opens in a new tab)
ItemRef sun::semantic_analysis::fieldRef(const sun::types::ClassType &cls, const sun::types::ClassField &f)Name a class field for a uniform access-denial message.
Members are owned by their type's module.
Related: ItemRef, sun::types::ClassType, sun::types::ClassField
fieldRef(const sun::types::InterfaceType &iface, const sun::types::InterfaceField &f)
public · function · Source (opens in a new tab)
ItemRef sun::semantic_analysis::fieldRef(const sun::types::InterfaceType &iface, const sun::types::InterfaceField &f)Name an interface field for a uniform access-denial message.
Creates the declaration reference used to check access to a field.
Related: ItemRef, sun::types::InterfaceType, sun::types::InterfaceField
findThisUse
public · function · Source (opens in a new tab)
const ExprAST * sun::semantic_analysis::findThisUse(const ExprAST &expr)The first this inside the expression, or null if there is none.
Finds the first this that belongs to the enclosing receiver.
Stops at a class or interface defined inside the expression, because a this in one of its methods refers to that type's own receiver, not the enclosing one.
Related: ExprAST
findVariableNode
public · function · Source (opens in a new tab)
const sun::ast::VariableCreationAST * sun::semantic_analysis::findVariableNode(const DeclarationTable &declarations, DeclarationId id)The node that declares a variable, or null when id is not a variable.
Related: sun::ast::VariableCreationAST, DeclarationTable, DeclarationId
forEachGlobalDeclaration
public · function · Source (opens in a new tab)
template <typename Fn>
void sun::semantic_analysis::forEachGlobalDeclaration(const sun::ast::BlockExprAST &block, Fn &&fn)Calls fn with each variable a block declares at file scope, in source order, looking inside modules and bundle scopes.
This is also the order in which startup initializes them.
Related: sun::ast::BlockExprAST
formatFunctionSignature
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::formatFunctionSignature(const std::string &name, const std::vector< sun::types::TypePtr > ¶mTypes)Format a function signature for diagnostics and scope inspection.
Formats a readable function signature for compiler diagnostics.
Related: sun::types::TypePtr
isAccessible
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isAccessible(DeclarationId from, const ItemRef &item, const DeclarationTable &table)Check visibility using the declaring module and its ancestors.
Reports whether the requesting declaration may access the target declaration.
Related: DeclarationId, ItemRef, DeclarationTable
isBorrowableLvalue
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isBorrowableLvalue(const ExprAST &target)A borrow binds the storage of an addressable lvalue: a variable, a field, or an array element.
Reports whether an expression denotes storage that can be borrowed.
Rejects everything else (temporaries, class __index__ results, slices), so ref r = x and var r: ref T = x agree.
Related: ExprAST
isFieldAccess
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isFieldAccess(const ExprAST &expr, std::string *ownerName=nullptr)True when expr names a field reached through a packed class at any depth.
Packing removes padding at that level, so everything nested beneath it inherits an arbitrary offset. Reports the offending class via ownerName.
Related: ExprAST
isImportScope
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isImportScope(const std::string &name)Helper to check if a module name represents an import scope ($import_...$).
isIntrinsic
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isIntrinsic(const std::string &name)True for an intrinsic function name.
Intrinsics live in the same reserved '' namespace, so this is the same test read the other way round: a call to a '' name is a call to the compiler, not to a declared function.
isLibraryHashSegment
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isLibraryHashSegment(const std::string &seg)Reports whether a module-path segment is an internal library hash.
isLibraryScope
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isLibraryScope(const std::string &name)Reports whether a scope name is a library's bundle hash ($hash$) rather than a module the program can name.
isReservedIdentifier
public · function · Source (opens in a new tab)
bool sun::semantic_analysis::isReservedIdentifier(const std::string &name)True for a name starting with '_', which is reserved for builtins.
Reserved identifiers are for builtins only (e.g.
User code may not declare one.
_is<T>, _sizeof<T>). The exception is the dunder methods a class implements to overload an operator: user code has to be able to spell those.
libraryHashOf
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::libraryHashOf(const std::string &seg)The hash inside a $hash$ segment ("$ab12$" gives "ab12"), or an empty string when the segment is not a library hash.
lvalueAlign
public · function · Source (opens in a new tab)
llvm::Align sun::semantic_analysis::lvalueAlign(const ExprAST &target, llvm::Type *slotTy, const llvm::DataLayout &DL)Alignment for an assignable expression, honouring the whole access chain.
Related: ExprAST
matchIsGuard
public · function · Source (opens in a new tab)
std::optional< IsGuard > sun::semantic_analysis::matchIsGuard(const ExprAST &cond)Recognizes the type-guard shape _is<T>(x), where x is a plain variable: a generic call of the _is intrinsic with one variable argument.
Matches the _is intrinsic applied to one variable reference.
Returns nothing for any other condition, or when T is a type trait such as _Integer, which tests a property and does not narrow to a type.
methodRef
methodRef(const sun::types::InterfaceType &iface, const sun::types::InterfaceMethod &m)
public · function · Source (opens in a new tab)
ItemRef sun::semantic_analysis::methodRef(const sun::types::InterfaceType &iface, const sun::types::InterfaceMethod &m)Name an interface method for a uniform access-denial message.
Creates the declaration reference used to check access to a method.
Related: ItemRef, sun::types::InterfaceType, sun::types::InterfaceMethod
methodRef(const sun::types::ClassType &cls, const sun::types::ClassMethod &m)
public · function · Source (opens in a new tab)
ItemRef sun::semantic_analysis::methodRef(const sun::types::ClassType &cls, const sun::types::ClassMethod &m)Name a class method for a uniform access-denial message.
Creates the declaration reference used to check access to a method.
Related: ItemRef, sun::types::ClassType, sun::types::ClassMethod
methodVisibility
public · function · Source (opens in a new tab)
Visibility sun::semantic_analysis::methodVisibility(const sun::ast::FunctionAST &method)deinit is compiler-invoked and therefore always public.
Constructors and destructors are always public: they are declared without a visibility keyword, and scope exit must be able to run deinit anywhere.
Related: Visibility, sun::ast::FunctionAST
moduleRef
public · function · Source (opens in a new tab)
ItemRef sun::semantic_analysis::moduleRef(const sun::semantic_analysis::ModuleScope &scope)Name a module for a uniform access-denial message.
Related: ItemRef, sun::semantic_analysis::ModuleScope
prepareFieldInitializers
public · function · Source (opens in a new tab)
void sun::semantic_analysis::prepareFieldInitializers(sun::ast::ClassDefinitionAST &classDef)Supplies default constructors and lowers field defaults before body analysis.
Prepares default field initializers for constructor analysis.
Related: sun::ast::ClassDefinitionAST
preparedBlockType
public · function · Source (opens in a new tab)
TypePtr sun::semantic_analysis::preparedBlockType(const sun::ast::BlockExprAST &block)The value type of an analyzed block: the type of its first return, else of its last statement when the block produces a value, else void.
Takes the type of the first return, else of the trailing value.
Related: sun::types::TypePtr, sun::ast::BlockExprAST
preparedMatchType
public · function · Source (opens in a new tab)
TypePtr sun::semantic_analysis::preparedMatchType(const sun::ast::MatchExprAST &match)The value type of an analyzed match: that of the first reachable arm whose body does not always leave (by return, throw, break or continue), else void.
Takes the type of the first reachable arm that yields a value.
Related: sun::types::TypePtr, sun::ast::MatchExprAST
reachableMatchArms
public · function · Source (opens in a new tab)
std::vector< const sun::ast::MatchArm * > sun::semantic_analysis::reachableMatchArms(const sun::ast::MatchExprAST &match)The arms of an analyzed match that can run: an arm for an enum variant an earlier arm already covers is left out, and nothing after the first _ arm is included.
Skips repeated enum variants and stops after the first wildcard.
Related: sun::ast::MatchArm, sun::ast::MatchExprAST
rejectDuplicateLifetimes
public · function · Source (opens in a new tab)
void sun::semantic_analysis::rejectDuplicateLifetimes(const std::vector< sun::ast::LifetimeParameter > ¶ms, const std::string &owner)Throws if two lifetime parameters share a name, pointing at the first.
owner is appended to the message, such as " on class 'Bus'", or empty.
Related: sun::ast::LifetimeParameter
rejectFieldType
public · function · Source (opens in a new tab)
std::string sun::semantic_analysis::rejectFieldType(const sun::types::TypePtr &fieldType)Why a field type is rejected inside a packed class, or empty if it is fine.
Multi-word fat pointers have interior pointers that would land unaligned for no benefit, and an unpacked nested class would reintroduce exactly the interior padding the user asked to remove.
Related: sun::types::TypePtr
rejectPartialMove
public · function · Source (opens in a new tab)
void sun::semantic_analysis::rejectPartialMove(const ExprAST &source, const sun::support::Position &loc)Throws when an owned value would be moved out of storage that must stay whole: an array element, a field reached through a reference or this, a field of a class with deinit, or a field of an indexed element.
Walks the access chain of a moved value looking for storage it must not leave.
Anything that copies or borrows on read passes.
Related: ExprAST, sun::support::Position
rejectRefEnvReturnType
public · function · Source (opens in a new tab)
void sun::semantic_analysis::rejectRefEnvReturnType(const std::optional< sun::ast::TypeAnnotation > &returnType, const sun::support::Position &location, bool allowNamed=false)Rejects a '<'_>' lambda type in return position: its captured environment lives in a stack frame that dies when the function returns.
With allowNamed, a lambda type whose frame has a lifetime name passes.
Related: sun::ast::TypeAnnotation, sun::support::Position
requireAccessible
public · function · Source (opens in a new tab)
void sun::semantic_analysis::requireAccessible(DeclarationId from, const ItemRef &item, const sun::support::Position &loc, const DeclarationTable &table)Reject a use outside the declaration's allowed module scope.
Reports a compiler error when the requesting declaration cannot access the target.
Related: DeclarationId, ItemRef, sun::support::Position, DeclarationTable
requireArguments
public · function · static · Source (opens in a new tab)
static std::vector< TypePtr > sun::semantic_analysis::requireArguments(sun::semantic_analysis::type_analysis::InferenceResult< std::vector< TypePtr > > result, const std::string &what, const std::string &displayName, std::optional< sun::support::Position > loc)Attach the call's name and location to an unsuccessful deduction.
Related: TypePtr, sun::semantic_analysis::type_analysis::InferenceResult, sun::support::Position
requireInferredType
public · function · Source (opens in a new tab)
sun::types::TypePtr sun::semantic_analysis::requireInferredType(sun::semantic_analysis::type_analysis::TypeResult result, const sun::support::Position &location, const std::string &message)Return an inferred type or report the caller's contextual diagnostic.
Related: sun::types::TypePtr, sun::semantic_analysis::type_analysis::TypeResult, sun::support::Position
requireResolvedType
public · function · Source (opens in a new tab)
TypePtr sun::semantic_analysis::requireResolvedType(const ExprAST &expr)The type analysis already recorded on the expression.
Returns the recorded type or reports that analysis skipped the node.
Throws an internal error if there is none, since callers rely on the expression having been analyzed first.
Related: sun::types::TypePtr, ExprAST
resolveGenericTypeArguments
resolveGenericTypeArguments(const sun::semantic_analysis::GenericFunctionInfo &genericInfo, const std::vector< sun::types::TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< sun::types::TypePtr > &explicitTypeArgs={})
public · function · Source (opens in a new tab)
std::vector< sun::types::TypePtr > sun::semantic_analysis::resolveGenericTypeArguments(const sun::semantic_analysis::GenericFunctionInfo &genericInfo, const std::vector< sun::types::TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< sun::types::TypePtr > &explicitTypeArgs={})Infer f<...> for a call written without type arguments, by matching the template's parameter annotations against the argument types.
A call may also name only the leading type parameters (f<i32>(x) for f<T, U>); those are passed as explicitTypeArgs and the rest are inferred. A result may still be a type parameter when the call sits in a template body. Throws a compile error naming the type parameter that could not be bound.
Related: sun::types::TypePtr, sun::semantic_analysis::GenericFunctionInfo, sun::support::Position
resolveGenericTypeArguments(const GenericFunctionInfo &genericInfo, const std::vector< TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< TypePtr > &explicitTypeArgs)
public · function · Source (opens in a new tab)
std::vector< TypePtr > sun::semantic_analysis::resolveGenericTypeArguments(const GenericFunctionInfo &genericInfo, const std::vector< TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< TypePtr > &explicitTypeArgs)No documentation comment.
Related: TypePtr, GenericFunctionInfo, sun::support::Position
resolveMethodTypeArguments
resolveMethodTypeArguments(const ClassMethod &method, const std::vector< TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< TypePtr > &explicitTypeArgs)
public · function · Source (opens in a new tab)
std::vector< TypePtr > sun::semantic_analysis::resolveMethodTypeArguments(const ClassMethod &method, const std::vector< TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< TypePtr > &explicitTypeArgs)No documentation comment.
Related: TypePtr, ClassMethod, sun::support::Position
resolveMethodTypeArguments(const sun::types::ClassMethod &method, const std::vector< sun::types::TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< sun::types::TypePtr > &explicitTypeArgs={})
public · function · Source (opens in a new tab)
std::vector< sun::types::TypePtr > sun::semantic_analysis::resolveMethodTypeArguments(const sun::types::ClassMethod &method, const std::vector< sun::types::TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc, const std::vector< sun::types::TypePtr > &explicitTypeArgs={})The same for a class method (obj.m(x), obj.m<i32>(x)), matching the method record's parameter types, in which the method's own type parameters appear as TypeParameterType.
Related: sun::types::TypePtr, sun::types::ClassMethod, sun::support::Position
shadowsGlobalVariable
public · function · static · Source (opens in a new tab)
static const SemanticScopeBase * sun::semantic_analysis::shadowsGlobalVariable(const SemanticScopeBase &scope, const std::string &name, DeclarationId declarationId)Returns the scope of a conflicting global or module variable, or null when the declaration does not shadow one.
Lookup stays within the current bundle.
Related: SemanticScopeBase, DeclarationId
splitModulePath
public · function · Source (opens in a new tab)
ModulePath sun::semantic_analysis::splitModulePath(const std::string &dotted)Splits a dotted module path into its individual names.
Related: ModulePath
splitPackArgTypes
splitPackArgTypes(const sun::ast::PrototypeAST &proto, const std::vector< sun::types::TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc)
public · function · Source (opens in a new tab)
std::optional< std::vector< sun::types::TypePtr > > sun::semantic_analysis::splitPackArgTypes(const sun::ast::PrototypeAST &proto, const std::vector< sun::types::TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc)A call's argument types, divided into the callee's fixed parameters and the remainder that fills its args... pack.
Returns the pack's share, or nullopt when the callee declares no pack. Errors when the call does not even cover the fixed parameters.
Related: sun::types::TypePtr, sun::ast::PrototypeAST, sun::support::Position
splitPackArgTypes(const sun::ast::PrototypeAST &proto, const std::vector< TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc)
public · function · Source (opens in a new tab)
std::optional< std::vector< TypePtr > > sun::semantic_analysis::splitPackArgTypes(const sun::ast::PrototypeAST &proto, const std::vector< TypePtr > &argTypes, const std::string &displayName, std::optional< sun::support::Position > loc)Everything after the fixed parameters belongs to the pack.
Related: TypePtr, sun::ast::PrototypeAST, sun::support::Position
toString
public · function · Source (opens in a new tab)
const char * sun::semantic_analysis::toString(ArgConversion conversion)Returns the diagnostic name of an argument conversion rule.
Returns a readable representation for diagnostics and debugging.
Related: ArgConversion
validateExternSignature
public · function · Source (opens in a new tab)
void sun::semantic_analysis::validateExternSignature(const sun::ast::FunctionAST &func)Rejects extern signatures that have no C spelling.
Primitives, raw_ptr<T>, ref T (C's T*) and objects by value all lower correctly; arrays, slices, interfaces and lambdas do not, and must error rather than silently miscompile. Needs the prototype's resolved types.
Related: sun::ast::FunctionAST
validateFieldNames
public · function · Source (opens in a new tab)
template <typename FieldDecl>
void sun::semantic_analysis::validateFieldNames(const std::vector< FieldDecl > &fields, const std::string &fieldKind, const std::string &owner)Checks each field name is not reserved and appears only once.
Works for class and interface fields alike. fieldKind names the fields in the reserved-name message ("Field name"); owner names the declaration in the duplicate message ("class 'Point'").
validateNotReserved
public · function · Source (opens in a new tab)
void sun::semantic_analysis::validateNotReserved(const std::string &name, const std::string &kind, std::optional< sun::support::Position > location)Throws if the name is reserved for builtins (it starts with '_').
kind names what is being declared in the message, such as "Class name".
Related: sun::support::Position
visibilityKeyword
public · function · Source (opens in a new tab)
const char * sun::semantic_analysis::visibilityKeyword(Visibility v)Returns the source keyword corresponding to an access level.
Related: Visibility
visibleModulePath
public · function · Source (opens in a new tab)
ModulePath sun::semantic_analysis::visibleModulePath(const ModulePath &path)The path as the program wrote it, without $hash$ or empty segments.
Related: ModulePath
Variables
All
public · variable · Source (opens in a new tab)
StructInfo sun::semantic_analysis::All[][] = {
{"closure", Layout::PtrPtr},
{"static_ptr_struct", Layout::PtrI64},
{"interface_fat", Layout::PtrPtr},
{"array_struct", Layout::PtrI32Ptr},
}No documentation comment.
Related: StructInfo, Layout::PtrPtr, Layout::PtrI64, Layout::PtrI32Ptr
ArrayStruct
public · variable · Source (opens in a new tab)
const char* sun::semantic_analysis::ArrayStruct = "array_struct"No documentation comment.
Closure
public · variable · Source (opens in a new tab)
const char* sun::semantic_analysis::Closure = "closure"No documentation comment.
Count
public · variable · Source (opens in a new tab)
size_t sun::semantic_analysis::Count = sizeof(All) / sizeof(All[0])No documentation comment.
Related: All
InterfaceFat
public · variable · Source (opens in a new tab)
const char* sun::semantic_analysis::InterfaceFat = "interface_fat"No documentation comment.
StaticPtr
public · variable · Source (opens in a new tab)
const char* sun::semantic_analysis::StaticPtr = "static_ptr_struct"No documentation comment.
Enums
ArgConversion
public · enum · Source (opens in a new tab)
enum class sun::semantic_analysis::ArgConversion : uint8_tThe conversion applied when an argument is matched to a parameter.
PassValue
PassValue
No documentation comment.
Move
Move
No documentation comment.
Borrow
Borrow
No documentation comment.
ArrayToView
ArrayToView
No documentation comment.
RawPtrAsRef
RawPtrAsRef
No documentation comment.
ClassToRefInterface
ClassToRefInterface
No documentation comment.
InterfaceRefUpcast
InterfaceRefUpcast
No documentation comment.
WidenNumeric
WidenNumeric
No documentation comment.
StaticToRawPtr
StaticToRawPtr
No documentation comment.
DerefRawPtr
DerefRawPtr
No documentation comment.
CVararg
CVararg
No documentation comment.
DeclarationKind
public · enum · Source (opens in a new tab)
enum class sun::semantic_analysis::DeclarationKindThe source role of a declaration, independent of its resolved type.
Module
Module = 0
No documentation comment.
Function
Function = 1
No documentation comment.
Lambda
Lambda = 2
No documentation comment.
Class
Class = 3
No documentation comment.
Interface
Interface = 4
No documentation comment.
Enum
Enum = 5
No documentation comment.
Variable
Variable = 6
No documentation comment.
Reference
Reference = 7
No documentation comment.
Parameter
Parameter = 8
No documentation comment.
TypeParameter
TypeParameter = 9
No documentation comment.
LifetimeParameter
LifetimeParameter = 10
No documentation comment.
Field
Field = 11
No documentation comment.
Variant
Variant = 12
No documentation comment.
Binding
Binding = 13
No documentation comment.
Alias
Alias = 14
No documentation comment.
Layout
public · enum · Source (opens in a new tab)
enum class sun::semantic_analysis::LayoutLayout patterns for well-known struct types.
Related: Layout
PtrPtr
PtrPtr
No documentation comment.
PtrI64
PtrI64
No documentation comment.
PtrI32Ptr
PtrI32Ptr
No documentation comment.
ScopeType
public · enum · Source (opens in a new tab)
enum class sun::semantic_analysis::ScopeTypeType of scope in the scope tree.
Related: Type
Global
Global
No documentation comment.
Module
Module
No documentation comment.
Import
Import
No documentation comment.
Class
Class
No documentation comment.
Interface
Interface
No documentation comment.
Function
Function
No documentation comment.
Block
Block
No documentation comment.
TypeParams
TypeParams
No documentation comment.
SymbolKind
public · enum · Source (opens in a new tab)
enum class sun::semantic_analysis::SymbolKindKind of symbol found during lookup.
None
None
No documentation comment.
Module
Module
No documentation comment.
Class
Class
No documentation comment.
GenericClass
GenericClass
No documentation comment.
Interface
Interface
No documentation comment.
GenericInterface
GenericInterface
No documentation comment.
Enum
Enum
No documentation comment.
Function
Function
No documentation comment.
GenericFunction
GenericFunction
No documentation comment.
Variable
Variable
No documentation comment.
Visibility
public · enum · Source (opens in a new tab)
enum class sun::semantic_analysis::Visibility : uint8_tThe access level used to control declaration lookup across scopes.
Private
Private = 0
No documentation comment.
Public
Public = 1
No documentation comment.
Type Aliases
ModulePath
public · typedef · Source (opens in a new tab)
using sun::semantic_analysis::ModulePath = std::vector<std::string>Module path segments used for source lookup and diagnostic display.
QualifiedName
public · typedef · Source (opens in a new tab)
using sun::semantic_analysis::QualifiedName = sun::semantic_analysis::QualifiedNameAlias for use in this header and semantic analyzer implementations.
SemanticScope
public · typedef · Source (opens in a new tab)
using sun::semantic_analysis::SemanticScope = SemanticScopeBaseAlias for backward compatibility.
Related: SemanticScopeBase