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

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

Issue 2841583002: Add FrontEndStrategy, ResolutionFrontEndStrategy and KernelFrontEndStrategy (Closed)
Patch Set: Updated cf. comments Created 3 years, 7 months 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 | « no previous file | pkg/compiler/lib/src/frontend_strategy.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 dart2js.compiler_base; 5 library dart2js.compiler_base;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import '../compiler_new.dart' as api; 9 import '../compiler_new.dart' as api;
10 import 'closure.dart' as closureMapping show ClosureTask; 10 import 'closure.dart' as closureMapping show ClosureTask;
(...skipping 14 matching lines...) Expand all
25 import 'common_elements.dart' show CommonElements, ElementEnvironment; 25 import 'common_elements.dart' show CommonElements, ElementEnvironment;
26 import 'deferred_load.dart' show DeferredLoadTask; 26 import 'deferred_load.dart' show DeferredLoadTask;
27 import 'diagnostics/code_location.dart'; 27 import 'diagnostics/code_location.dart';
28 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; 28 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter;
29 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; 29 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION;
30 import 'diagnostics/messages.dart' show Message, MessageTemplate; 30 import 'diagnostics/messages.dart' show Message, MessageTemplate;
31 import 'dump_info.dart' show DumpInfoTask; 31 import 'dump_info.dart' show DumpInfoTask;
32 import 'elements/elements.dart'; 32 import 'elements/elements.dart';
33 import 'elements/entities.dart'; 33 import 'elements/entities.dart';
34 import 'elements/modelx.dart' show ErroneousElementX; 34 import 'elements/modelx.dart' show ErroneousElementX;
35 import 'elements/resolution_types.dart' 35 import 'elements/resolution_types.dart' show ResolutionDartType, Types;
36 show
37 ResolutionDartType,
38 ResolutionDynamicType,
39 ResolutionFunctionType,
40 ResolutionInterfaceType,
41 Types;
42 import 'elements/types.dart' show DartTypes; 36 import 'elements/types.dart' show DartTypes;
43 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; 37 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer;
44 import 'environment.dart'; 38 import 'environment.dart';
39 import 'frontend_strategy.dart';
45 import 'id_generator.dart'; 40 import 'id_generator.dart';
46 import 'io/source_information.dart' show SourceInformation; 41 import 'io/source_information.dart' show SourceInformation;
47 import 'js_backend/backend.dart' show JavaScriptBackend; 42 import 'js_backend/backend.dart' show JavaScriptBackend;
43 import 'kernel/kernel_strategy.dart';
48 import 'library_loader.dart' 44 import 'library_loader.dart'
49 show 45 show
50 ElementScanner, 46 ElementScanner,
51 LibraryLoader, 47 LibraryLoader,
52 LibraryLoaderTask, 48 LibraryLoaderTask,
53 LoadedLibraries, 49 LoadedLibraries,
54 LibraryProvider,
55 ScriptLoader; 50 ScriptLoader;
56 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; 51 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask;
57 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; 52 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink;
58 import 'options.dart' show CompilerOptions, DiagnosticOptions; 53 import 'options.dart' show CompilerOptions, DiagnosticOptions;
59 import 'parser/diet_parser_task.dart' show DietParserTask; 54 import 'parser/diet_parser_task.dart' show DietParserTask;
60 import 'parser/parser_task.dart' show ParserTask; 55 import 'parser/parser_task.dart' show ParserTask;
61 import 'patch_parser.dart' show PatchParserTask; 56 import 'patch_parser.dart' show PatchParserTask;
62 import 'resolution/resolution.dart' show ResolverTask; 57 import 'resolution/resolution.dart' show ResolverTask;
58 import 'resolution/resolution_strategy.dart';
63 import 'resolved_uri_translator.dart'; 59 import 'resolved_uri_translator.dart';
64 import 'scanner/scanner_task.dart' show ScannerTask; 60 import 'scanner/scanner_task.dart' show ScannerTask;
65 import 'script.dart' show Script; 61 import 'script.dart' show Script;
66 import 'serialization/task.dart' show SerializationTask; 62 import 'serialization/task.dart' show SerializationTask;
67 import 'ssa/nodes.dart' show HInstruction; 63 import 'ssa/nodes.dart' show HInstruction;
68 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; 64 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token;
69 import 'tokens/token_map.dart' show TokenMap; 65 import 'tokens/token_map.dart' show TokenMap;
70 import 'tree/tree.dart' show Node, TypeAnnotation; 66 import 'tree/tree.dart' show Node, TypeAnnotation;
71 import 'typechecker.dart' show TypeCheckerTask; 67 import 'typechecker.dart' show TypeCheckerTask;
72 import 'types/types.dart' show GlobalTypeInferenceTask; 68 import 'types/types.dart' show GlobalTypeInferenceTask;
73 import 'universe/call_structure.dart' show CallStructure; 69 import 'universe/call_structure.dart' show CallStructure;
74 import 'universe/selector.dart' show Selector; 70 import 'universe/selector.dart' show Selector;
75 import 'universe/world_builder.dart' 71 import 'universe/world_builder.dart'
76 show ResolutionWorldBuilder, CodegenWorldBuilder; 72 show ResolutionWorldBuilder, CodegenWorldBuilder;
77 import 'universe/use.dart' show StaticUse, TypeUse; 73 import 'universe/use.dart' show StaticUse, TypeUse;
78 import 'universe/world_impact.dart' 74 import 'universe/world_impact.dart'
79 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; 75 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl;
80 import 'util/util.dart' show Link; 76 import 'util/util.dart' show Link;
81 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; 77 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl;
82 78
83 typedef CompilerDiagnosticReporter MakeReporterFunction( 79 typedef CompilerDiagnosticReporter MakeReporterFunction(
84 Compiler compiler, CompilerOptions options); 80 Compiler compiler, CompilerOptions options);
85 81
86 abstract class Compiler { 82 abstract class Compiler {
87 Measurer get measurer; 83 Measurer get measurer;
88 84
89 final IdGenerator idGenerator = new IdGenerator(); 85 final IdGenerator idGenerator = new IdGenerator();
90 DartTypes types; 86 DartTypes types;
87 FrontEndStrategy frontEndStrategy;
91 CommonElements _commonElements; 88 CommonElements _commonElements;
92 _CompilerElementEnvironment _elementEnvironment; 89 ElementEnvironment _elementEnvironment;
93 CompilerDiagnosticReporter _reporter; 90 CompilerDiagnosticReporter _reporter;
94 CompilerResolution _resolution; 91 CompilerResolution _resolution;
95 ParsingContext _parsingContext; 92 ParsingContext _parsingContext;
96 93
97 ImpactStrategy impactStrategy = const ImpactStrategy(); 94 ImpactStrategy impactStrategy = const ImpactStrategy();
98 95
99 /** 96 /**
100 * Map from token to the first preceding comment token. 97 * Map from token to the first preceding comment token.
101 */ 98 */
102 final TokenMap commentMap = new TokenMap(); 99 final TokenMap commentMap = new TokenMap();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 MakeReporterFunction makeReporter}) 185 MakeReporterFunction makeReporter})
189 : this.options = options, 186 : this.options = options,
190 this.userOutputProvider = outputProvider == null 187 this.userOutputProvider = outputProvider == null
191 ? const NullCompilerOutput() 188 ? const NullCompilerOutput()
192 : outputProvider { 189 : outputProvider {
193 if (makeReporter != null) { 190 if (makeReporter != null) {
194 _reporter = makeReporter(this, options); 191 _reporter = makeReporter(this, options);
195 } else { 192 } else {
196 _reporter = new CompilerDiagnosticReporter(this, options); 193 _reporter = new CompilerDiagnosticReporter(this, options);
197 } 194 }
195 frontEndStrategy = options.loadFromDill
196 ? new KernelFrontEndStrategy(reporter)
197 : new ResolutionFrontEndStrategy(this);
198 _resolution = createResolution(); 198 _resolution = createResolution();
199 _elementEnvironment = new _CompilerElementEnvironment(this); 199 _elementEnvironment = frontEndStrategy.elementEnvironment;
200 _commonElements = new CommonElements(_elementEnvironment); 200 _commonElements = new CommonElements(_elementEnvironment);
201 types = new Types(_resolution); 201 types = new Types(_resolution);
202 202
203 if (options.verbose) { 203 if (options.verbose) {
204 progress = new Stopwatch()..start(); 204 progress = new Stopwatch()..start();
205 } 205 }
206 206
207 backend = createBackend(); 207 backend = createBackend();
208 enqueuer = backend.makeEnqueuer(); 208 enqueuer = backend.makeEnqueuer();
209 209
210 tasks = [ 210 tasks = [
211 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), 211 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer),
212 scanner = createScannerTask(), 212 scanner = createScannerTask(),
213 serialization = new SerializationTask(this), 213 serialization = new SerializationTask(this),
214 patchParser = new PatchParserTask(this), 214 patchParser = new PatchParserTask(this),
215 libraryLoader = new LibraryLoaderTask( 215 libraryLoader = frontEndStrategy.createLibraryLoader(
216 options.loadFromDill,
217 resolvedUriTranslator, 216 resolvedUriTranslator,
218 options.compileOnly 217 options.compileOnly
219 ? new _NoScriptLoader(this) 218 ? new _NoScriptLoader(this)
220 : new _ScriptLoader(this), 219 : new _ScriptLoader(this),
221 new _ElementScanner(scanner), 220 new _ElementScanner(scanner),
222 serialization, 221 serialization,
223 resolvePatchUri, 222 resolvePatchUri,
224 patchParser, 223 patchParser,
225 environment, 224 environment,
226 reporter, 225 reporter,
(...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 _ElementScanner(this.scanner); 1742 _ElementScanner(this.scanner);
1744 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); 1743 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library);
1745 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); 1744 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit);
1746 } 1745 }
1747 1746
1748 class _EmptyEnvironment implements Environment { 1747 class _EmptyEnvironment implements Environment {
1749 const _EmptyEnvironment(); 1748 const _EmptyEnvironment();
1750 1749
1751 String valueOf(String key) => null; 1750 String valueOf(String key) => null;
1752 } 1751 }
1753
1754 /// An element environment base on a [Compiler].
1755 class _CompilerElementEnvironment implements ElementEnvironment {
1756 final Compiler _compiler;
1757
1758 _CompilerElementEnvironment(this._compiler);
1759
1760 LibraryProvider get _libraryProvider => _compiler.libraryLoader;
1761 Resolution get _resolution => _compiler.resolution;
1762
1763 ResolutionDynamicType get dynamicType => const ResolutionDynamicType();
1764
1765 @override
1766 LibraryEntity get mainLibrary => _compiler.mainApp;
1767
1768 @override
1769 FunctionEntity get mainFunction => _compiler.mainFunction;
1770
1771 @override
1772 Iterable<LibraryEntity> get libraries => _compiler.libraryLoader.libraries;
1773
1774 @override
1775 ResolutionInterfaceType getThisType(ClassElement cls) {
1776 cls.ensureResolved(_resolution);
1777 return cls.thisType;
1778 }
1779
1780 @override
1781 ResolutionInterfaceType getRawType(ClassElement cls) {
1782 cls.ensureResolved(_resolution);
1783 return cls.rawType;
1784 }
1785
1786 @override
1787 ResolutionDartType getTypeVariableBound(TypeVariableElement typeVariable) {
1788 return typeVariable.bound;
1789 }
1790
1791 @override
1792 ResolutionInterfaceType createInterfaceType(
1793 ClassElement cls, List<ResolutionDartType> typeArguments) {
1794 cls.ensureResolved(_resolution);
1795 return cls.thisType.createInstantiation(typeArguments);
1796 }
1797
1798 @override
1799 bool isSubtype(ResolutionDartType a, ResolutionDartType b) {
1800 return _compiler.types.isSubtype(a, b);
1801 }
1802
1803 @override
1804 MemberElement lookupClassMember(ClassElement cls, String name,
1805 {bool setter: false, bool required: false}) {
1806 cls.ensureResolved(_resolution);
1807 Element member = cls.implementation.lookupLocalMember(name);
1808 if (member != null && member.isAbstractField) {
1809 AbstractFieldElement abstractField = member;
1810 if (setter) {
1811 member = abstractField.setter;
1812 } else {
1813 member = abstractField.getter;
1814 }
1815 if (member == null && required) {
1816 throw new SpannableAssertionFailure(
1817 cls,
1818 "The class '${cls.name}' does not contain required "
1819 "${setter ? 'setter' : 'getter'}: '$name'.");
1820 }
1821 }
1822 if (member == null && required) {
1823 throw new SpannableAssertionFailure(
1824 cls,
1825 "The class '${cls.name}' does not "
1826 "contain required member: '$name'.");
1827 }
1828 return member?.declaration;
1829 }
1830
1831 @override
1832 ConstructorElement lookupConstructor(ClassElement cls, String name,
1833 {bool required: false}) {
1834 cls.ensureResolved(_resolution);
1835 ConstructorElement constructor = cls.implementation.lookupConstructor(name);
1836 if (constructor == null && required) {
1837 throw new SpannableAssertionFailure(
1838 cls,
1839 "The class '${cls.name}' does not contain "
1840 "required constructor: '$name'.");
1841 }
1842 return constructor?.declaration;
1843 }
1844
1845 @override
1846 void forEachClassMember(
1847 ClassElement cls, void f(ClassElement declarer, MemberElement member)) {
1848 cls.ensureResolved(_resolution);
1849 cls.forEachMember((ClassElement declarer, MemberElement member) {
1850 if (member.isSynthesized) return;
1851 if (member.isMalformed) return;
1852 f(declarer, member);
1853 }, includeSuperAndInjectedMembers: true);
1854 }
1855
1856 @override
1857 ClassEntity getSuperClass(ClassElement cls) => cls.superclass;
1858
1859 @override
1860 void forEachSupertype(
1861 ClassElement cls, void f(ResolutionInterfaceType supertype)) {
1862 cls.allSupertypes
1863 .forEach((ResolutionInterfaceType supertype) => f(supertype));
1864 }
1865
1866 @override
1867 void forEachMixin(ClassElement cls, void f(ClassElement mixin)) {
1868 for (; cls != null; cls = cls.superclass) {
1869 if (cls.isMixinApplication) {
1870 MixinApplicationElement mixinApplication = cls;
1871 f(mixinApplication.mixin);
1872 }
1873 }
1874 }
1875
1876 @override
1877 MemberElement lookupLibraryMember(LibraryElement library, String name,
1878 {bool setter: false, bool required: false}) {
1879 Element member = library.implementation.findLocal(name);
1880 if (member != null && member.isAbstractField) {
1881 AbstractFieldElement abstractField = member;
1882 if (setter) {
1883 member = abstractField.setter;
1884 } else {
1885 member = abstractField.getter;
1886 }
1887 if (member == null && required) {
1888 throw new SpannableAssertionFailure(
1889 library,
1890 "The library '${library.canonicalUri}' does not contain required "
1891 "${setter ? 'setter' : 'getter'}: '$name'.");
1892 }
1893 }
1894 if (member == null && required) {
1895 throw new SpannableAssertionFailure(
1896 member,
1897 "The library '${library.libraryName}' does not "
1898 "contain required member: '$name'.");
1899 }
1900 return member?.declaration;
1901 }
1902
1903 @override
1904 ClassElement lookupClass(LibraryElement library, String name,
1905 {bool required: false}) {
1906 ClassElement cls = library.implementation.findLocal(name);
1907 if (cls == null && required) {
1908 throw new SpannableAssertionFailure(
1909 cls,
1910 "The library '${library.libraryName}' does not "
1911 "contain required class: '$name'.");
1912 }
1913 return cls?.declaration;
1914 }
1915
1916 @override
1917 void forEachClass(LibraryElement library, void f(ClassElement cls)) {
1918 library.implementation.forEachLocalMember((member) {
1919 if (member.isClass) {
1920 f(member);
1921 }
1922 });
1923 }
1924
1925 @override
1926 LibraryElement lookupLibrary(Uri uri, {bool required: false}) {
1927 LibraryElement library = _libraryProvider.lookupLibrary(uri);
1928 // If the script of the library is synthesized, the library does not exist
1929 // and we do not try to load the helpers.
1930 //
1931 // This could for example happen if dart:async is disabled, then loading it
1932 // should not try to find the given element.
1933 if (library != null && library.isSynthesized) {
1934 return null;
1935 }
1936 if (library == null && required) {
1937 throw new SpannableAssertionFailure(
1938 library, "The library '${uri}' was not found.");
1939 }
1940 return library;
1941 }
1942
1943 @override
1944 CallStructure getCallStructure(MethodElement method) {
1945 ResolutionFunctionType type = method.computeType(_resolution);
1946 return new CallStructure(
1947 type.parameterTypes.length +
1948 type.optionalParameterTypes.length +
1949 type.namedParameterTypes.length,
1950 type.namedParameters);
1951 }
1952
1953 @override
1954 bool isDeferredLoadLibraryGetter(MemberElement member) {
1955 return member.isDeferredLoaderGetter;
1956 }
1957
1958 @override
1959 ResolutionFunctionType getFunctionType(MethodElement method) {
1960 method.computeType(_resolution);
1961 return method.type;
1962 }
1963
1964 @override
1965 ResolutionFunctionType getLocalFunctionType(LocalFunctionElement function) {
1966 return function.type;
1967 }
1968
1969 @override
1970 ResolutionDartType getUnaliasedType(ResolutionDartType type) {
1971 type.computeUnaliased(_resolution);
1972 return type.unaliased;
1973 }
1974 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/frontend_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698