Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Enhancements to the Module System #1428

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
16ba5ad
Update configuration files
leeyi45 Jun 22, 2023
c1a51dd
Add async module loading code and tests
leeyi45 Jun 22, 2023
f8e3311
Add general utils
leeyi45 Jun 22, 2023
40b1eb3
Add helper types
leeyi45 Jun 22, 2023
d639512
Move preprocessor to modules folder
leeyi45 Jun 22, 2023
6d81ad4
Relocate ast creator to new utils folder
leeyi45 Jun 22, 2023
8acfd79
Add AST utils and relocate walkers
leeyi45 Jun 22, 2023
b00153e
Clean version of async-imports3
leeyi45 Jun 22, 2023
a1f47f4
Ran format
leeyi45 Jun 22, 2023
ef8d903
Update error tests
leeyi45 Jun 22, 2023
150e94e
Ran format
leeyi45 Jun 22, 2023
509be3b
Update snapshot
leeyi45 Jun 22, 2023
d565099
Remove unnecessary code
leeyi45 Jun 22, 2023
92d7b48
Clean up ec-evaluator implementation for imports
leeyi45 Jun 23, 2023
d493ffa
Fix accumulate working in the wrong direction
leeyi45 Jun 23, 2023
3ba38ef
Ran format
leeyi45 Jun 23, 2023
813cceb
Update list test to take initial argument into account
leeyi45 Jun 23, 2023
2a2ac1f
Add missing tests
leeyi45 Jun 23, 2023
ba1cc1b
Ran format
leeyi45 Jun 23, 2023
532a944
Ran format
leeyi45 Jun 23, 2023
fbbb690
Add tests for length()
leeyi45 Jun 28, 2023
24ec58b
Merge commit '8618e26e47595bdeb609857d7d3265cde09beb37' into async-im…
leeyi45 Jun 28, 2023
43481bb
Ensure that moduleLoaderAsync properly handles fetch type errors
leeyi45 Jun 28, 2023
9ed1e54
Fix broken error handling
leeyi45 Jun 28, 2023
0380f5e
Add test to ensure that TypeErrors thrown by fetch are caught
leeyi45 Jun 28, 2023
d67af01
Fix fetch not timing out when modules server is unreachable
leeyi45 Jul 14, 2023
bc6a53f
Ran format
leeyi45 Jul 14, 2023
fb49b56
fix(deps): update all non-major dependencies
renovate[bot] Jul 19, 2023
bd4b132
Merge from master
leeyi45 Jul 19, 2023
1e05b13
Update @types/node
leeyi45 Jul 19, 2023
d1e5800
Ran format
leeyi45 Jul 19, 2023
937bae9
Update stepper
leeyi45 Jul 29, 2023
d330c39
Move module mocking to individual tests
leeyi45 Jul 29, 2023
d06a2ca
Refactor ast utils
leeyi45 Jul 30, 2023
f66472d
Fix broken path
leeyi45 Jul 30, 2023
157cd3b
Add no rexport declaration rule
leeyi45 Jul 30, 2023
545f558
fix(deps): update all non-major dependencies
renovate[bot] Jul 31, 2023
fd901b9
Add no reexport declaration rule
leeyi45 Aug 1, 2023
8553c76
Ensure reexport rule is not enforced for FullJS
leeyi45 Aug 1, 2023
f4fc2e2
Update code to use type guards
leeyi45 Aug 1, 2023
2b7eb11
Ran format
leeyi45 Aug 1, 2023
cdbac82
Revert node types change temporarily
leeyi45 Aug 1, 2023
a3d9c4d
Merge commit '545f558853f44e377aca8822074ea1730f42921e' into async-im…
leeyi45 Aug 1, 2023
59dbf48
Ran format
leeyi45 Aug 1, 2023
dfb5882
Update stepper and tests for async
leeyi45 Aug 2, 2023
0dc35cc
Add tests for ArrayMap
leeyi45 Aug 2, 2023
5f8f68e
Fix broken tests
leeyi45 Aug 2, 2023
f264219
Update code to use ArrayMap
leeyi45 Aug 2, 2023
b05f072
Update node types
leeyi45 Aug 2, 2023
a8f3951
Update node types
leeyi45 Aug 2, 2023
657ab8c
Remove global mocks entirely
leeyi45 Aug 2, 2023
9913230
Fix tests not working with wrap-ansi
leeyi45 Aug 2, 2023
288af5d
Ran format
leeyi45 Aug 2, 2023
703da37
Merge branch 'master' into async-imports-clean
martin-henz Aug 7, 2023
1d75fa2
Merge branch 'master' into async-imports-clean
martin-henz Aug 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
dist/
.idea/
coverage/
yarn-error.log

# emacs backup files
*~
Expand Down
16 changes: 16 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SourceMapConsumer } from "source-map"

jest.mock('lodash', () => ({
...jest.requireActual('lodash'),
memoize: jest.fn((x: any) => x),
}))

jest.mock('./src/modules/moduleLoaderAsync')
jest.mock('./src/modules/moduleLoader')

// @ts-ignore
SourceMapConsumer.initialize({
'lib/mappings.wasm': 'https://unpkg.com/source-map@0.7.3/lib/mappings.wasm'
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that this is needed for the source-map library to work in browsers (aa58f3d). Is this really needed for the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running tests on my system, without this code in jest.setup.ts causes TypeError: Cannot read properties of undefined (reading 'then') when running certain tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I can't replicate this locally. Logically, this shouldn't be needed in a Node.js environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I just don't really know where the issue is, or how to resolve it at the moment


global.fetch = jest.fn()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to mock only the functions/classes that each test suite needs within the test suite itself for the same reasons that we always try to reduce the scope of variables. If we were to declare all of our mocks here, you can imagine that it would very quickly become hard to keep track of which mocks are used in which test suite as new test cases are added/updated over time.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"/src/scm-slang",
"/src/py-slang/"
],
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.ts"
],
"reporters": [
"default",
[
Expand Down
2 changes: 1 addition & 1 deletion src/ec-evaluator/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { loadModuleBundle, loadModuleTabs } from '../modules/moduleLoader'
import { ModuleFunctions } from '../modules/moduleTypes'
import { checkEditorBreakpoints } from '../stdlib/inspector'
import { Context, ContiguousArrayElements, Result, Value } from '../types'
import * as ast from '../utils/astCreator'
import * as ast from '../utils/ast/astCreator'
import { evaluateBinaryExpression, evaluateUnaryExpression } from '../utils/operators'
import * as rttc from '../utils/rttc'
import * as instr from './instrCreator'
Expand Down
2 changes: 1 addition & 1 deletion src/ec-evaluator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as errors from '../errors/errors'
import { RuntimeSourceError } from '../errors/runtimeSourceError'
import Closure from '../interpreter/closure'
import { Environment, Frame, Value } from '../types'
import * as ast from '../utils/astCreator'
import * as ast from '../utils/ast/astCreator'
import * as instr from './instrCreator'
import { Agenda } from './interpreter'
import { AgendaItem, AppInstr, AssmtInstr, Instr, InstrType } from './types'
Expand Down
2 changes: 1 addition & 1 deletion src/errors/localImportErrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UNKNOWN_LOCATION } from '../constants'
import { nonAlphanumericCharEncoding } from '../localImports/filePaths'
import { nonAlphanumericCharEncoding } from '../modules/preprocessor/filePaths'
import { ErrorSeverity, ErrorType, SourceError } from '../types'

export abstract class InvalidFilePathError implements SourceError {
Expand Down
2 changes: 1 addition & 1 deletion src/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
FullWalkerCallback,
recursive,
WalkerCallback
} from './utils/walkers'
} from './utils/ast/walkers'

// Finds the innermost node that matches the given location
export function findIdentifierNode(
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/gpu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as es from 'estree'

import * as create from '../utils/astCreator'
import * as create from '../utils/ast/astCreator'
import { getIdentifiersInProgram } from '../utils/uniqueIds'
import GPUTransformer from './transfomer'

Expand Down
4 changes: 2 additions & 2 deletions src/gpu/transfomer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as es from 'estree'

import * as create from '../utils/astCreator'
import { ancestor, make, simple } from '../utils/walkers'
import * as create from '../utils/ast/astCreator'
import { ancestor, make, simple } from '../utils/ast/walkers'
import GPUBodyVerifier from './verification/bodyVerifier'
import GPULoopVerifier from './verification/loopVerifier'

Expand Down
2 changes: 1 addition & 1 deletion src/gpu/verification/bodyVerifier.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as es from 'estree'

import { make, simple } from '../../utils/walkers'
import { make, simple } from '../../utils/ast/walkers'

/*
* GPU Body verifier helps to ensure the body is parallelizable
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import {
SVMProgram,
Variant
} from './types'
import { findNodeAt } from './utils/walkers'
import { findNodeAt } from './utils/ast/walkers'
import { assemble } from './vm/svml-assembler'
import { compileToIns } from './vm/svml-compiler'
export { SourceDocumentation } from './editors/ace/docTooltip'
import * as es from 'estree'

import { ECEResultPromise, resumeEvaluate } from './ec-evaluator/interpreter'
import { CannotFindModuleError } from './errors/localImportErrors'
import { validateFilePath } from './localImports/filePaths'
import preprocessFileImports from './localImports/preprocessor'
import { validateFilePath } from './modules/preprocessor/filePaths'
import preprocessFileImports from './modules/preprocessor/preprocessor'
import { getKeywords, getProgramNames, NameDeclaration } from './name-extractor'
import { parse } from './parser/parser'
import { parseWithComments } from './parser/utils'
Expand Down
2 changes: 1 addition & 1 deletion src/infiniteLoops/detect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generate } from 'astring'
import * as es from 'estree'

import { simple } from '../utils/walkers'
import { simple } from '../utils/ast/walkers'
import { InfiniteLoopError, InfiniteLoopErrorType } from './errors'
import { getOriginalName } from './instrument'
import * as st from './state'
Expand Down
4 changes: 2 additions & 2 deletions src/infiniteLoops/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { generate } from 'astring'
import * as es from 'estree'

import { transformImportDeclarations } from '../transpiler/transpiler'
import * as create from '../utils/astCreator'
import { recursive, simple, WalkerCallback } from '../utils/walkers'
import * as create from '../utils/ast/astCreator'
import { recursive, simple, WalkerCallback } from '../utils/ast/walkers'
// transforms AST of program

const globalIds = {
Expand Down
2 changes: 1 addition & 1 deletion src/infiniteLoops/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRequireProvider } from '../modules/requireProvider'
import { parse } from '../parser/parser'
import * as stdList from '../stdlib/list'
import { Chapter, Variant } from '../types'
import * as create from '../utils/astCreator'
import * as create from '../utils/ast/astCreator'
import { checkForInfiniteLoop } from './detect'
import { InfiniteLoopError } from './errors'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/infiniteLoops/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { generate } from 'astring'
import * as es from 'estree'

import { identifier } from '../utils/astCreator'
import { identifier } from '../utils/ast/astCreator'
import * as sym from './symbolic'

// Object + functions called during runtime to check for infinite loops
Expand Down
2 changes: 1 addition & 1 deletion src/infiniteLoops/symbolic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as es from 'estree'

import * as create from '../utils/astCreator'
import * as create from '../utils/ast/astCreator'
import { evaluateBinaryExpression, evaluateUnaryExpression } from '../utils/operators'

// data structure for symbolic + hybrid values
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/closure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
callExpression,
identifier,
returnStatement
} from '../utils/astCreator'
} from '../utils/ast/astCreator'
import { dummyLocation } from '../utils/dummyAstCreator'
import { apply } from './interpreter'

Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/interpreter-non-det.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CUT, UNKNOWN_LOCATION } from '../constants'
import * as errors from '../errors/errors'
import { RuntimeSourceError } from '../errors/runtimeSourceError'
import { Context, Environment, Frame, Value } from '../types'
import { conditionalExpression, literal, primitive } from '../utils/astCreator'
import { conditionalExpression, literal, primitive } from '../utils/ast/astCreator'
import { evaluateBinaryExpression, evaluateUnaryExpression } from '../utils/operators'
import * as rttc from '../utils/rttc'
import Closure from './closure'
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { loadModuleBundle, loadModuleTabs } from '../modules/moduleLoader'
import { ModuleFunctions } from '../modules/moduleTypes'
import { checkEditorBreakpoints } from '../stdlib/inspector'
import { Context, ContiguousArrayElements, Environment, Frame, Value, Variant } from '../types'
import * as create from '../utils/astCreator'
import { conditionalExpression, literal, primitive } from '../utils/astCreator'
import * as create from '../utils/ast/astCreator'
import { conditionalExpression, literal, primitive } from '../utils/ast/astCreator'
import { evaluateBinaryExpression, evaluateUnaryExpression } from '../utils/operators'
import * as rttc from '../utils/rttc'
import Closure from './closure'
Expand Down
4 changes: 2 additions & 2 deletions src/lazy/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as es from 'estree'

import * as create from '../utils/astCreator'
import * as create from '../utils/ast/astCreator'
import { getIdentifiersInProgram } from '../utils/uniqueIds'
import { simple } from '../utils/walkers'
import { simple } from '../utils/ast/walkers'

const lazyPrimitives = new Set(['makeLazyFunction', 'wrapLazyCallee', 'forceIt', 'delayIt'])

Expand Down
17 changes: 8 additions & 9 deletions src/modules/__tests__/moduleLoader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { createEmptyContext } from '../../createContext'
import { ModuleConnectionError, ModuleInternalError } from '../../errors/moduleErrors'
import { Variant } from '../../types'
import { stripIndent } from '../../utils/formatters'
import * as moduleLoader from '../moduleLoader'
import { ModuleConnectionError, ModuleInternalError } from '../errors'

// Mock memoize function from lodash
jest.mock('lodash', () => ({ memoize: jest.fn(func => func) }))
const moduleLoader = jest.requireActual('../moduleLoader')

/**
* Mock XMLHttpRequest from jsdom environment
Expand Down Expand Up @@ -80,7 +78,7 @@ describe('Testing modules/moduleLoader.ts in a jsdom environment', () => {
const sampleResponse = `(function () {'use strict'; function index(_params) { return { }; } return index; })();`
const correctUrl = moduleLoader.MODULES_STATIC_URL + `/bundles/${validModuleBundle}.js`
const mockedXMLHttpRequest = mockXMLHttpRequest({ responseText: sampleResponse })
const response = moduleLoader.memoizedGetModuleFile(validModuleBundle, 'bundle')
const response = moduleLoader.memoizedGetBundle(validModuleBundle)
expect(mockedXMLHttpRequest.open).toHaveBeenCalledTimes(1)
expect(mockedXMLHttpRequest.open).toHaveBeenCalledWith('GET', correctUrl, false)
expect(mockedXMLHttpRequest.send).toHaveBeenCalledTimes(1)
Expand All @@ -93,7 +91,7 @@ describe('Testing modules/moduleLoader.ts in a jsdom environment', () => {
const sampleResponse = `(function (React) {});`
const correctUrl = moduleLoader.MODULES_STATIC_URL + `/tabs/${validModuleTab}.js`
const mockedXMLHttpRequest = mockXMLHttpRequest({ responseText: sampleResponse })
const response = moduleLoader.memoizedGetModuleFile(validModuleTab, 'tab')
const response = moduleLoader.memoizedGetTab(validModuleTab)
expect(mockedXMLHttpRequest.open).toHaveBeenCalledTimes(1)
expect(mockedXMLHttpRequest.open).toHaveBeenCalledWith('GET', correctUrl, false)
expect(mockedXMLHttpRequest.send).toHaveBeenCalledTimes(1)
Expand All @@ -112,7 +110,8 @@ describe('Testing modules/moduleLoader.ts in a jsdom environment', () => {
mockXMLHttpRequest({ responseText: sampleResponse })
const loadedBundle = moduleLoader.loadModuleBundle(
'module',
createEmptyContext(1, Variant.DEFAULT, [])
createEmptyContext(1, Variant.DEFAULT, []),
false
)
expect(loadedBundle.make_empty_array()).toEqual([])
})
Expand All @@ -123,7 +122,7 @@ describe('Testing modules/moduleLoader.ts in a jsdom environment', () => {
const wrongModuleText = `export function es6_function(params) {};`
mockXMLHttpRequest({ responseText: wrongModuleText })
expect(() =>
moduleLoader.loadModuleBundle('module', createEmptyContext(1, Variant.DEFAULT, []))
moduleLoader.loadModuleBundle('module', createEmptyContext(1, Variant.DEFAULT, []), false)
).toThrow(ModuleInternalError)
})

Expand Down Expand Up @@ -183,4 +182,4 @@ describe('Testing modules/moduleLoader.ts in a jsdom environment', () => {
expect(mockedXMLHttpRequest3.send).toHaveBeenCalledTimes(1)
expect(mockedXMLHttpRequest3.send).toHaveBeenCalledWith(null)
})
})
})
Loading