Skip to content

Commit 0780899

Browse files
ZweZeyamartin-henz
andauthored
1395 remove hints type inference (#1522)
* comment out typeCheck * Revert "comment out typeCheck" This reverts commit f51b1bb. * remove type inferences by removing getTypeInformation and typeCheck * remove typeChecker and tests --------- Co-authored-by: Martin Henz <[email protected]>
1 parent 79c7695 commit 0780899

File tree

3 files changed

+1
-3833
lines changed

3 files changed

+1
-3833
lines changed

src/index.ts

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SourceMapConsumer } from 'source-map'
44
import createContext from './createContext'
55
import { InterruptedError } from './errors/errors'
66
import { findDeclarationNode, findIdentifierNode } from './finder'
7-
import { looseParse, typedParse } from './parser/utils'
7+
import { looseParse } from './parser/utils'
88
import { getAllOccurrencesInScopeHelper, getScopeHelper } from './scope-refactoring'
99
import { setBreakpointAtLine } from './stdlib/inspector'
1010
import {
@@ -13,16 +13,13 @@ import {
1313
Error as ResultError,
1414
ExecutionMethod,
1515
Finished,
16-
FuncDeclWithInferredTypeAnnotation,
1716
ModuleContext,
18-
NodeWithInferredType,
1917
RecursivePartial,
2018
Result,
2119
SourceError,
2220
SVMProgram,
2321
Variant
2422
} from './types'
25-
import { findNodeAt } from './utils/walkers'
2623
import { assemble } from './vm/svml-assembler'
2724
import { compileToIns } from './vm/svml-compiler'
2825
export { SourceDocumentation } from './editors/ace/docTooltip'
@@ -44,8 +41,6 @@ import {
4441
resolvedErrorPromise,
4542
sourceFilesRunner
4643
} from './runner'
47-
import { typeCheck } from './typeChecker/typeChecker'
48-
import { typeToString } from './utils/stringify'
4944

5045
export interface IOptions {
5146
scheduler: 'preemptive' | 'async'
@@ -202,108 +197,6 @@ export async function getNames(
202197
return [progNames.concat(keywords), displaySuggestions]
203198
}
204199

205-
export function getTypeInformation(
206-
code: string,
207-
context: Context,
208-
loc: { line: number; column: number },
209-
name: string
210-
): string {
211-
try {
212-
// parse the program into typed nodes and parse error
213-
const program = typedParse(code, context)
214-
if (program === null) {
215-
return ''
216-
}
217-
if (context.prelude !== null) {
218-
typeCheck(typedParse(context.prelude, context)!, context)
219-
}
220-
const [typedProgram, error] = typeCheck(program, context)
221-
const parsedError = parseError(error)
222-
if (context.prelude !== null) {
223-
// the env of the prelude was added, we now need to remove it
224-
context.typeEnvironment.pop()
225-
}
226-
227-
// initialize the ans string
228-
let ans = ''
229-
if (parsedError) {
230-
ans += parsedError + '\n'
231-
}
232-
if (!typedProgram) {
233-
return ans
234-
}
235-
236-
// get name of the node
237-
const getName = (typedNode: NodeWithInferredType<es.Node>) => {
238-
let nodeId = ''
239-
if (typedNode.type) {
240-
if (typedNode.type === 'FunctionDeclaration') {
241-
if (typedNode.id === null) {
242-
throw new Error(
243-
'Encountered a FunctionDeclaration node without an identifier. This should have been caught when parsing.'
244-
)
245-
}
246-
nodeId = typedNode.id.name
247-
} else if (typedNode.type === 'VariableDeclaration') {
248-
nodeId = (typedNode.declarations[0].id as es.Identifier).name
249-
} else if (typedNode.type === 'Identifier') {
250-
nodeId = typedNode.name
251-
}
252-
}
253-
return nodeId
254-
}
255-
256-
// callback function for findNodeAt function
257-
function findByLocationPredicate(t: string, nd: NodeWithInferredType<es.Node>) {
258-
if (!nd.inferredType) {
259-
return false
260-
}
261-
262-
const isInLoc = (nodeLoc: SourceLocation): boolean => {
263-
return !(
264-
nodeLoc.start.line > loc.line ||
265-
nodeLoc.end.line < loc.line ||
266-
(nodeLoc.start.line === loc.line && nodeLoc.start.column > loc.column) ||
267-
(nodeLoc.end.line === loc.line && nodeLoc.end.column < loc.column)
268-
)
269-
}
270-
271-
const location = nd.loc
272-
if (nd.type && location) {
273-
return getName(nd) === name && isInLoc(location)
274-
}
275-
return false
276-
}
277-
278-
// report both as the type inference
279-
280-
const res = findNodeAt(typedProgram, undefined, undefined, findByLocationPredicate)
281-
282-
if (res === undefined) {
283-
return ans
284-
}
285-
286-
const node: NodeWithInferredType<es.Node> = res.node
287-
288-
if (node === undefined) {
289-
return ans
290-
}
291-
292-
const actualNode =
293-
node.type === 'VariableDeclaration'
294-
? (node.declarations[0].init! as NodeWithInferredType<es.Node>)
295-
: node
296-
const type = typeToString(
297-
actualNode.type === 'FunctionDeclaration'
298-
? (actualNode as FuncDeclWithInferredTypeAnnotation).functionInferredType!
299-
: actualNode.inferredType!
300-
)
301-
return ans + `At Line ${loc.line} => ${getName(node)}: ${type}`
302-
} catch (error) {
303-
return ''
304-
}
305-
}
306-
307200
export async function runInContext(
308201
code: string,
309202
context: Context,

0 commit comments

Comments
 (0)