@@ -91,29 +91,11 @@ class DiagnoseUnknownCompileTimeValues : public SILModuleTransform {
9191 }
9292 }
9393
94- void verifyStaticallyInitializedGlobal (ConstExprFunctionState &ConstExprState,
95- SILGlobalVariable &Global,
96- VarDecl *Decl) {
97- LLVM_DEBUG (llvm::dbgs ()
98- << " @const static let " << Decl->getName ().str ().str ()
99- << " : " << Decl->getTypeInContext ().getString () << " = " ;);
100- auto StaticInitializerValue = Global.getStaticInitializerValue ();
101- assert (StaticInitializerValue && " Expected a static initializer" );
102- if (auto *SI = dyn_cast<StructInst>(StaticInitializerValue)) {
103- for (auto &SIO : SI->getAllOperands ()) {
104- if (!ConstExprState.getConstantValue (SIO.get ())
105- .containsOnlyConstants ()) {
106- Decl->diagnose (diag::require_const_initializer_for_const);
107- LLVM_DEBUG (llvm::dbgs () << " Unknown\n " ;);
108- } else
109- LLVM_DEBUG (printSymbolicValueValue (
110- ConstExprState.getConstantValue (SIO.get ()), Allocator));
111- }
112- }
113- }
114-
11594 void verifyInitializeOnceGlobal (ConstExprFunctionState &ConstExprState,
11695 SILGlobalVariable &Global, VarDecl *Decl) {
96+ // TODO: Determine cases if/where this is necessary to perform,
97+ // i.e. where we currently fail to simplify to a statically-initialized
98+ // value.
11799 LLVM_DEBUG (llvm::dbgs ()
118100 << " @const [init_once] let " << Decl->getName ().str ().str ()
119101 << " : " << Decl->getTypeInContext ().getString () << " = " ;);
@@ -129,19 +111,11 @@ class DiagnoseUnknownCompileTimeValues : public SILModuleTransform {
129111 for (SILInstruction &I : BB) {
130112 if (auto *GlobalAddr = dyn_cast<GlobalAddrInst>(&I)) {
131113 if (GlobalAddr->getReferencedGlobal () == &Global) {
132- // Get the sole store to the global addr
133- // ACTODO: check if single use valid/exists
134- // Find sole store
135- // for (auto *use : getNonDebugUses(existentialBox)) {
136- // worklist.insert(use);
137- // }
138-
139114 if (auto SingleUse = GlobalAddr->getSingleUse ()) {
140115 auto SoleUseUser = SingleUse->getUser ();
141116 assert (isa<StoreInst>(SoleUseUser));
142- auto Value = ConstExprState.getConstantValue (
143- dyn_cast<StoreInst>(SoleUseUser)->getSrc ());
144-
117+ auto src = dyn_cast<StoreInst>(SoleUseUser)->getSrc ();
118+ auto Value = ConstExprState.getConstantValue (src);
145119 if (Value.isConstant ()) {
146120 LLVM_DEBUG (printSymbolicValueValue (Value, Allocator););
147121 return ;
@@ -165,9 +139,29 @@ class DiagnoseUnknownCompileTimeValues : public SILModuleTransform {
165139 for (SILGlobalVariable &G : M->getSILGlobals ()) {
166140 if (auto Decl = G.getDecl ()) {
167141 if (Decl->isConstVal ()) {
168- if (G.getStaticInitializerValue ())
169- verifyStaticallyInitializedGlobal (ConstExprState, G, Decl);
170- else
142+ if (G.getStaticInitializerValue ()) {
143+ // Presence of a static initializer alone confirms
144+ // this to be a constant value.
145+ LLVM_DEBUG (
146+ llvm::dbgs ()
147+ << " @const static let " << Decl->getName ().str ().str ()
148+ << " : " << Decl->getTypeInContext ().getString () << " = " ;
149+ auto StaticInitializerValue = G.getStaticInitializerValue ();
150+ assert (StaticInitializerValue &&
151+ " Expected a static initializer" );
152+ if (auto *SI = dyn_cast<StructInst>(StaticInitializerValue)) {
153+ for (auto &SIO : SI->getAllOperands ()) {
154+ if (!ConstExprState.getConstantValue (SIO.get ())
155+ .containsOnlyConstants ())
156+ LLVM_DEBUG (llvm::dbgs ()
157+ << " Unknown to the Constant Evaluator\n " ;);
158+ else
159+ LLVM_DEBUG (printSymbolicValueValue (
160+ ConstExprState.getConstantValue (SIO.get ()),
161+ Allocator));
162+ }
163+ });
164+ } else
171165 verifyInitializeOnceGlobal (ConstExprState, G, Decl);
172166 }
173167 }
@@ -244,8 +238,8 @@ class DiagnoseUnknownCompileTimeValues : public SILModuleTransform {
244238 printSymbolicValueValue (Value, Allocator);
245239 });
246240 if (!ConstExprState.getConstantValue (CorrespondingArg).isConstant ()) {
247- // FIXME: Is there a way to get this source loc without going throuh
248- // the ApplyExpr?
241+ // FIXME: Is there a way to get this source loc without going
242+ // throuh the ApplyExpr?
249243 auto ArgLocation = Apply->getLoc ().getSourceLoc ();
250244 if (auto ApplyExprNode = Apply->getLoc ().getAsASTNode <ApplyExpr>())
251245 ArgLocation = ApplyExprNode->getArgs ()[i].getLoc ();
0 commit comments