Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: pkg/compiler/lib/src/types/types.dart

Issue 2569733002: Even less reliance on Compiler.closedWorld (Closed)
Patch Set: Updated cf. comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/types/masks.dart ('k') | pkg/compiler/lib/src/universe/world_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library types; 5 library types;
6 6
7 import '../closure.dart' show SynthesizedCallMethodElementX; 7 import '../closure.dart' show SynthesizedCallMethodElementX;
8 import '../common.dart' show invariant; 8 import '../common.dart' show invariant;
9 import '../common/tasks.dart' show CompilerTask; 9 import '../common/tasks.dart' show CompilerTask;
10 import '../compiler.dart' show Compiler; 10 import '../compiler.dart' show Compiler;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 /// Results produced by the global type-inference algorithm. 179 /// Results produced by the global type-inference algorithm.
180 /// 180 ///
181 /// All queries in this class may contain results that assume whole-program 181 /// All queries in this class may contain results that assume whole-program
182 /// closed-world semantics. Any [TypeMask] for an element or node that we return 182 /// closed-world semantics. Any [TypeMask] for an element or node that we return
183 /// was inferred to be a "guaranteed type", that means, it is a type that we 183 /// was inferred to be a "guaranteed type", that means, it is a type that we
184 /// can prove to be correct for all executions of the program. 184 /// can prove to be correct for all executions of the program.
185 class GlobalTypeInferenceResults { 185 class GlobalTypeInferenceResults {
186 // TODO(sigmund): store relevant data & drop reference to inference engine. 186 // TODO(sigmund): store relevant data & drop reference to inference engine.
187 final TypeGraphInferrer _inferrer; 187 final TypeGraphInferrer _inferrer;
188 final Compiler compiler; 188 final ClosedWorld closedWorld;
189 final TypeMask dynamicType; 189 final Compiler _compiler;
190 final Map<Element, GlobalTypeInferenceElementResult> _elementResults = {}; 190 final Map<Element, GlobalTypeInferenceElementResult> _elementResults = {};
191 191
192 // TODO(sigmund,johnniwinther): compute result objects eagerly and make it an 192 // TODO(sigmund,johnniwinther): compute result objects eagerly and make it an
193 // error to query for results that don't exist. 193 // error to query for results that don't exist.
194 GlobalTypeInferenceElementResult resultOf(AstElement element) { 194 GlobalTypeInferenceElementResult resultOf(AstElement element) {
195 assert(invariant(element, !element.isGenerativeConstructorBody, 195 assert(invariant(element, !element.isGenerativeConstructorBody,
196 message: "unexpected input: ConstructorBodyElements are created" 196 message: "unexpected input: ConstructorBodyElements are created"
197 " after global type inference, no data is avaiable for them.")); 197 " after global type inference, no data is avaiable for them."));
198 198
199 // TODO(sigmund): store closure data directly in the closure element and 199 // TODO(sigmund): store closure data directly in the closure element and
200 // not in the context of the enclosing method? 200 // not in the context of the enclosing method?
201 var key = (element is SynthesizedCallMethodElementX) 201 var key = (element is SynthesizedCallMethodElementX)
202 ? element.memberContext 202 ? element.memberContext
203 : element; 203 : element;
204 return _elementResults.putIfAbsent( 204 return _elementResults.putIfAbsent(
205 element, 205 element,
206 () => new GlobalTypeInferenceElementResultImpl( 206 () => new GlobalTypeInferenceElementResultImpl(
207 element, 207 element,
208 _inferrer.inferrer.inTreeData[key], 208 _inferrer.inferrer.inTreeData[key],
209 _inferrer, 209 _inferrer,
210 compiler.backend.isJsInterop(element), 210 _compiler.backend.isJsInterop(element),
211 dynamicType)); 211 dynamicType));
212 } 212 }
213 213
214 GlobalTypeInferenceResults(this._inferrer, this.compiler, CommonMasks masks, 214 GlobalTypeInferenceResults(this._inferrer, this._compiler, this.closedWorld,
215 TypeInformationSystem types) 215 TypeInformationSystem types);
216 : dynamicType = masks.dynamicType; 216
217 TypeMask get dynamicType => closedWorld.commonMasks.dynamicType;
217 218
218 /// Returns the type of a [selector] when applied to a receiver with the given 219 /// Returns the type of a [selector] when applied to a receiver with the given
219 /// type [mask]. 220 /// type [mask].
220 TypeMask typeOfSelector(Selector selector, TypeMask mask) => 221 TypeMask typeOfSelector(Selector selector, TypeMask mask) =>
221 _inferrer.getTypeOfSelector(selector, mask); 222 _inferrer.getTypeOfSelector(selector, mask);
222 223
223 /// Returns whether a fixed-length constructor call goes through a growable 224 /// Returns whether a fixed-length constructor call goes through a growable
224 /// check. 225 /// check.
225 // TODO(sigmund): move into the result of the element containing such 226 // TODO(sigmund): move into the result of the element containing such
226 // constructor call. 227 // constructor call.
(...skipping 20 matching lines...) Expand all
247 248
248 /// Runs the global type-inference algorithm once. 249 /// Runs the global type-inference algorithm once.
249 void runGlobalTypeInference(Element mainElement, ClosedWorld closedWorld, 250 void runGlobalTypeInference(Element mainElement, ClosedWorld closedWorld,
250 ClosedWorldRefiner closedWorldRefiner) { 251 ClosedWorldRefiner closedWorldRefiner) {
251 measure(() { 252 measure(() {
252 typesInferrerInternal ??= 253 typesInferrerInternal ??=
253 new TypeGraphInferrer(compiler, closedWorld, closedWorldRefiner); 254 new TypeGraphInferrer(compiler, closedWorld, closedWorldRefiner);
254 typesInferrerInternal.analyzeMain(mainElement); 255 typesInferrerInternal.analyzeMain(mainElement);
255 typesInferrerInternal.clear(); 256 typesInferrerInternal.clear();
256 results = new GlobalTypeInferenceResults(typesInferrerInternal, compiler, 257 results = new GlobalTypeInferenceResults(typesInferrerInternal, compiler,
257 closedWorld.commonMasks, typesInferrerInternal.inferrer.types); 258 closedWorld, typesInferrerInternal.inferrer.types);
258 }); 259 });
259 } 260 }
260 } 261 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/types/masks.dart ('k') | pkg/compiler/lib/src/universe/world_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698