@@ -42,6 +42,7 @@ namespace swift {
4242 class AutoClosureExpr ;
4343 class ASTContext ;
4444 class ClassDecl ;
45+ class FileUnit ;
4546 class SILFunctionType ;
4647 enum IsSerialized_t : unsigned char ;
4748 enum class SubclassScope : unsigned char ;
@@ -83,7 +84,14 @@ enum ForDefinition_t : bool {
8384// / declaration, such as uncurry levels of a function, the allocating and
8485// / initializing entry points of a constructor, etc.
8586struct SILDeclRef {
86- using Loc = llvm::PointerUnion<ValueDecl *, AbstractClosureExpr *>;
87+ // / The type of AST node location being stored.
88+ enum LocKind {
89+ Decl,
90+ Closure,
91+ File
92+ };
93+ using Loc = llvm::PointerUnion<ValueDecl *, AbstractClosureExpr *,
94+ FileUnit *>;
8795
8896 // / Represents the "kind" of the SILDeclRef. For some Swift decls there
8997 // / are multiple SIL entry points, and the kind is used to distinguish them.
@@ -144,9 +152,16 @@ struct SILDeclRef {
144152 // / References the function used to initialize a property wrapper storage
145153 // / instance from a projected value.
146154 PropertyWrapperInitFromProjectedValue,
155+
156+ // / The main entry-point function. This may reference a SourceFile for a
157+ // / top-level main, or a decl for e.g an @main decl.
158+ EntryPoint,
159+
160+ // / The asynchronous main entry-point function.
161+ AsyncEntryPoint,
147162 };
148-
149- // / The ValueDecl or AbstractClosureExpr represented by this SILDeclRef.
163+
164+ // / The AST node represented by this SILDeclRef.
150165 Loc loc;
151166 // / The Kind of this SILDeclRef.
152167 Kind kind : 4 ;
@@ -159,6 +174,17 @@ struct SILDeclRef {
159174 const GenericSignatureImpl *>
160175 pointer;
161176
177+ // / Returns the type of AST node location being stored by the SILDeclRef.
178+ LocKind getLocKind () const {
179+ if (loc.is <ValueDecl *>())
180+ return LocKind::Decl;
181+ if (loc.is <AbstractClosureExpr *>())
182+ return LocKind::Closure;
183+ if (loc.is <FileUnit *>())
184+ return LocKind::File;
185+ llvm_unreachable (" Unhandled location kind!" );
186+ }
187+
162188 // / The derivative function identifier.
163189 AutoDiffDerivativeFunctionIdentifier * getDerivativeFunctionIdentifier () const {
164190 if (!pointer.is <AutoDiffDerivativeFunctionIdentifier *>())
@@ -201,6 +227,15 @@ struct SILDeclRef {
201227 // / Produce a SIL constant for a default argument generator.
202228 static SILDeclRef getDefaultArgGenerator (Loc loc, unsigned defaultArgIndex);
203229
230+ // / Produces a SILDeclRef for a synthetic main entry-point such as @main.
231+ static SILDeclRef getMainDeclEntryPoint (ValueDecl *decl);
232+
233+ // / Produces a SILDeclRef for the synthesized async main entry-point
234+ static SILDeclRef getAsyncMainDeclEntryPoint (ValueDecl *decl);
235+
236+ // / Produces a SILDeclRef for the entry-point of a main FileUnit.
237+ static SILDeclRef getMainFileEntryPoint (FileUnit *file);
238+
204239 bool isNull () const { return loc.isNull (); }
205240 explicit operator bool () const { return !isNull (); }
206241
@@ -217,7 +252,13 @@ struct SILDeclRef {
217252 AutoClosureExpr *getAutoClosureExpr () const ;
218253 FuncDecl *getFuncDecl () const ;
219254 AbstractFunctionDecl *getAbstractFunctionDecl () const ;
220-
255+ FileUnit *getFileUnit () const {
256+ return loc.get <FileUnit *>();
257+ }
258+
259+ // / Retrieves the ASTContext from the underlying AST node being stored.
260+ ASTContext &getASTContext () const ;
261+
221262 llvm::Optional<AnyFunctionRef> getAnyFunctionRef () const ;
222263
223264 SILLocation getAsRegularLocation () const ;
0 commit comments