MCPcopy Create free account
hub / github.com/Snapchat/Valdi / compileNative

Function compileNative

compiler/companion/src/native/CompileNativeCommand.ts:117–219  ·  view source on GitHub ↗
(
  workspace: Workspace,
  logger: ILogger | undefined,
  request: CompileNativeRequestBody,
)

Source from the content-addressed store, hash-verified

115}
116
117export async function compileNative(
118 workspace: Workspace,
119 logger: ILogger | undefined,
120 request: CompileNativeRequestBody,
121): Promise<CompileNativeResponseBody> {
122 const filesToOpen: string[] = [];
123
124 for (const inputFile of request.inputFiles) {
125 let relativePath: string;
126 if (request.registerInputFiles) {
127 const stripIndex = inputFile.indexOf(request.stripIncludePrefix);
128 if (stripIndex < 0) {
129 throw new Error(`Invalid strip include prefix '${request.stripIncludePrefix}' for file path ${inputFile}`);
130 }
131 relativePath = inputFile.substring(stripIndex + request.stripIncludePrefix.length + 1);
132
133 workspace.registerDiskFile(relativePath, inputFile);
134 } else {
135 relativePath = inputFile;
136 }
137
138 if (
139 (inputFile.endsWith('.ts') && !inputFile.endsWith('.d.ts')) ||
140 inputFile.endsWith('.tsx') ||
141 inputFile.endsWith('.js')
142 ) {
143 filesToOpen.push(relativePath);
144 }
145 }
146
147 if (!workspace.initialized) {
148 await workspace.initialize();
149 }
150
151 const openedFiles = await Promise.all(filesToOpen.map((file) => workspace.openFile(file)));
152 const allIRs: NativeCompilerIR.Base[] = [];
153 const shouldCheckSyntax = !!request.registerInputFiles;
154
155 const options = {
156 optimizeSlots: true,
157 optimizeVarRefs: true,
158
159 // smaller code size and faster
160 optimizeNullChecks: true,
161 mergeSetProperties: true,
162 foldConstants: true,
163 optimizeVarRefLoads: true,
164 optimizeAssignments: true,
165 inlinePropertyCache: true,
166 enableIntrinsics: true, // unsafe, replace some builtin functions with intrinsics
167
168 mergeReleases: false, // smaller code size, very slightly slower
169 autoRelease: false, // smaller code size, slightly slower
170 noinlineRetainRelease: false, // smaller code size, slower
171 };
172 let fileIndex = 0;
173 for (const openedFile of openedFiles) {
174 const relativePath = filesToOpen[fileIndex];

Callers 1

addBaseEndpointsMethod · 0.90

Calls 15

compileIRsToCFunction · 0.90
compileFileFunction · 0.85
generateNativeModuleNameFunction · 0.85
substringMethod · 0.80
debugMethod · 0.80
registerDiskFileMethod · 0.65
initializeMethod · 0.65
allMethod · 0.65
openFileMethod · 0.65
errorMethod · 0.65
indexOfMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected