diff --git a/packages/debugger/lib/data/actions/index.js b/packages/debugger/lib/data/actions/index.js index 721d859e024..698f0c96e92 100644 --- a/packages/debugger/lib/data/actions/index.js +++ b/packages/debugger/lib/data/actions/index.js @@ -11,12 +11,12 @@ export function scope(id, pointer, parentId, sourceId, compilationId) { } export const DECLARE = "DATA_DECLARE_VARIABLE"; -export function declare(name, idOrPath, scopeIdOrPath, compilationId) { +export function declare(name, astRef, scopeAstRef, compilationId) { return { type: DECLARE, name, - idOrPath, - scopeIdOrPath, + astRef, + scopeAstRef, compilationId }; } diff --git a/packages/debugger/lib/data/reducers.js b/packages/debugger/lib/data/reducers.js index 79c100824a0..a06c9a70d0e 100644 --- a/packages/debugger/lib/data/reducers.js +++ b/packages/debugger/lib/data/reducers.js @@ -20,7 +20,11 @@ function scopes(state = DEFAULT_SCOPES, action) { switch (action.type) { case actions.SCOPE: { const { compilationId, id, sourceId, parentId, pointer } = action; - const idOrPath = id !== undefined ? id : makePath(sourceId, pointer); + const astRef = id !== undefined ? id : makePath(sourceId, pointer); + //astRef is used throughout the data saga. + //it identifies an AST node within a given compilation either by: + //1. its ast ID, if it has one, or + //2. a combination of its source index and its JSON pointer if not newState = { byCompilationId: { @@ -35,14 +39,14 @@ function scopes(state = DEFAULT_SCOPES, action) { newState.byCompilationId[compilationId] = { ...newState.byCompilationId[compilationId], - byIdOrPath: { - ...newState.byCompilationId[compilationId].byIdOrPath + byAstRef: { + ...newState.byCompilationId[compilationId].byAstRef } }; - scope = newState.byCompilationId[compilationId].byIdOrPath[idOrPath]; + scope = newState.byCompilationId[compilationId].byAstRef[astRef]; - newState.byCompilationId[compilationId].byIdOrPath[idOrPath] = { + newState.byCompilationId[compilationId].byAstRef[astRef] = { ...scope, id, sourceId, @@ -55,11 +59,10 @@ function scopes(state = DEFAULT_SCOPES, action) { } case actions.DECLARE: { - let { compilationId, name, idOrPath, scopeIdOrPath } = action; + let { compilationId, name, astRef, scopeAstRef } = action; //note: we can assume the compilation already exists! - scope = - state.byCompilationId[compilationId].byIdOrPath[scopeIdOrPath] || {}; + scope = state.byCompilationId[compilationId].byAstRef[scopeAstRef] || {}; variables = scope.variables || []; return { @@ -67,10 +70,10 @@ function scopes(state = DEFAULT_SCOPES, action) { ...state.byCompilationId, [compilationId]: { ...state.byCompilationId[compilationId], - byIdOrPath: { - ...state.byCompilationId[compilationId].byIdOrPath, + byAstRef: { + ...state.byCompilationId[compilationId].byAstRef, - [scopeIdOrPath]: { + [scopeAstRef]: { ...scope, variables: [ @@ -78,7 +81,7 @@ function scopes(state = DEFAULT_SCOPES, action) { { name, - idOrPath, + astRef, compilationId } ] @@ -169,7 +172,7 @@ function assignments(state = DEFAULT_ASSIGNMENTS, action) { debug("action.type %O", action.type); debug("action.assignments %O", action.assignments); return Object.values(action.assignments).reduce((acc, assignment) => { - let { id, idOrPath, compilationId } = assignment; + let { id, astRef, compilationId } = assignment; //we assume for now that only ordinary variables will be assigned this //way, and not globals; globals are handled in DEFAULT_ASSIGNMENTS return { @@ -182,12 +185,12 @@ function assignments(state = DEFAULT_ASSIGNMENTS, action) { ...acc.byCompilationId, [compilationId]: { ...acc.byCompilationId[compilationId], - byIdOrPath: { - ...(acc.byCompilationId[compilationId] || {}).byIdOrPath, - [idOrPath]: [ + byAstRef: { + ...(acc.byCompilationId[compilationId] || {}).byAstRef, + [astRef]: [ ...new Set([ - ...(((acc.byCompilationId[compilationId] || {}) - .byIdOrPath || {})[idOrPath] || []), + ...(((acc.byCompilationId[compilationId] || {}).byAstRef || + {})[astRef] || []), id ]) ] diff --git a/packages/debugger/lib/data/sagas/index.js b/packages/debugger/lib/data/sagas/index.js index 4ac5ef9fbbd..c4c0d97d540 100644 --- a/packages/debugger/lib/data/sagas/index.js +++ b/packages/debugger/lib/data/sagas/index.js @@ -382,13 +382,13 @@ function* variablesAndMappingsSaga() { inModifier ? { compilationId, - idOrPath: sourceAndPointer, + astRef: sourceAndPointer, stackframe: currentDepth, modifierDepth } : { compilationId, - idOrPath: sourceAndPointer, + astRef: sourceAndPointer, stackframe: currentDepth }, { @@ -412,7 +412,7 @@ function* variablesAndMappingsSaga() { assignments = {}; for (let id in allocation.members) { id = Number(id); //not sure why we're getting them as strings, but... - let idObj = { compilationId, idOrPath: id, address }; + let idObj = { compilationId, astRef: id, address }; let fullId = stableKeccak256(idObj); //we don't use makeAssignment here as we had to compute the ID anyway assignment = { @@ -461,11 +461,11 @@ function* variablesAndMappingsSaga() { inModifier ? { compilationId, - idOrPath: varId, + astRef: varId, stackframe: currentDepth, modifierDepth } - : { compilationId, idOrPath: varId, stackframe: currentDepth }, + : { compilationId, astRef: varId, stackframe: currentDepth }, { location: "stack", from: top - Codec.Ast.Utils.stackSize(node) + 1, @@ -512,13 +512,13 @@ function* variablesAndMappingsSaga() { inModifier ? { compilationId, - idOrPath: variableSourceAndPointer, + astRef: variableSourceAndPointer, stackframe: currentDepth, modifierDepth } : { compilationId, - idOrPath: variableSourceAndPointer, + astRef: variableSourceAndPointer, stackframe: currentDepth }, { @@ -785,11 +785,11 @@ function* decodeMappingKeyCore(indexDefinition, keyDefinition) { let indexIdObj = inModifier ? { compilationId, - idOrPath: indexId, + astRef: indexId, stackframe: currentDepth, modifierDepth } - : { compilationId, idOrPath: indexId, stackframe: currentDepth }; + : { compilationId, astRef: indexId, stackframe: currentDepth }; let fullIndexId = stableKeccak256(indexIdObj); const indexReference = (currentAssignments.byId[fullIndexId] || {}).ref; @@ -971,11 +971,11 @@ function literalAssignments( inModifier ? { compilationId, - idOrPath: node.id, + astRef: node.id, stackframe: currentDepth, modifierDepth } - : { compilationId, idOrPath: node.id, stackframe: currentDepth }, + : { compilationId, astRef: node.id, stackframe: currentDepth }, { location: "stackliteral", literal } ); @@ -1009,11 +1009,11 @@ function assignParameters( forModifier ? { compilationId, - idOrPath: parameter.id, + astRef: parameter.id, stackframe: functionDepth, modifierDepth } - : { compilationId, idOrPath: parameter.id, stackframe: functionDepth }, + : { compilationId, astRef: parameter.id, stackframe: functionDepth }, pointer ); assignments[assignment.id] = assignment; @@ -1035,13 +1035,13 @@ function fetchBasePath( inModifier ? { compilationId, - idOrPath: baseNode.id, + astRef: baseNode.id, stackframe: currentDepth, modifierDepth } : { compilationId, - idOrPath: baseNode.id, + astRef: baseNode.id, stackframe: currentDepth } ); diff --git a/packages/debugger/lib/data/selectors/index.js b/packages/debugger/lib/data/selectors/index.js index 0115ea372ab..f8c6ba4ef56 100644 --- a/packages/debugger/lib/data/selectors/index.js +++ b/packages/debugger/lib/data/selectors/index.js @@ -224,7 +224,7 @@ const data = createSelectorTree({ ) .filter( variable => - inlined[compilationId][variable.idOrPath].definition + inlined[compilationId][variable.astRef].definition .visibility !== "private" //filter out private variables from the base classes ) @@ -236,7 +236,7 @@ const data = createSelectorTree({ //how to read. they'll just clutter things up. debug("variable %O", variable); let definition = - inlined[compilationId][variable.idOrPath].definition; + inlined[compilationId][variable.astRef].definition; return ( !definition.constant || Codec.Ast.Utils.isSimpleConstant(definition.value) @@ -261,7 +261,7 @@ const data = createSelectorTree({ Object.assign( {}, ...Object.entries(scopes.byCompilationId).map( - ([compilationId, { byIdOrPath: nodes }]) => ({ + ([compilationId, { byAstRef: nodes }]) => ({ [compilationId]: { ...nodes } }) ) @@ -1059,7 +1059,7 @@ const data = createSelectorTree({ * data.current.identifiers (selector) * * returns identifers and corresponding definition node ID or builtin name - * (object entries look like [name]: {idOrPath: idOrPath}, [name]: {builtin: name}) + * (object entries look like [name]: {astRef: astRef}, [name]: {builtin: name}) */ _: createLeaf( [ @@ -1082,7 +1082,7 @@ const data = createSelectorTree({ .filter(variable => variable.name !== "") //exclude anonymous output params .filter(variable => variables[variable.name] == undefined) //don't add shadowed vars .map(variable => ({ - [variable.name]: { idOrPath: variable.idOrPath } + [variable.name]: { astRef: variable.astRef } })) ); //NOTE: because these assignments are processed in order, that means @@ -1141,8 +1141,8 @@ const data = createSelectorTree({ let variables = Object.assign( {}, ...Object.entries(identifiers).map(([identifier, variable]) => { - if (variable.idOrPath !== undefined) { - let { definition } = scopes[variable.idOrPath]; + if (variable.astRef !== undefined) { + let { definition } = scopes[variable.astRef]; return { [identifier]: definition }; //there used to be separate code for Yul variables here, //but now that's handled in definitionToType @@ -1211,18 +1211,18 @@ const data = createSelectorTree({ Object.assign( {}, ...Object.entries(identifiers).map( - ([identifier, { idOrPath, builtin }]) => { + ([identifier, { astRef, builtin }]) => { let id; - debug("idOrPath: %o", idOrPath); + debug("astRef: %o", astRef); debug("builtin: %s", builtin); //is this an ordinary variable or a builtin? - if (idOrPath !== undefined) { + if (astRef !== undefined) { //if not a builtin, first check if it's a contract var let compilationAssignments = (assignments.byCompilationId[compilationId] || {}) - .byIdOrPath || {}; - id = (compilationAssignments[idOrPath] || []).find( + .byAstRef || {}; + id = (compilationAssignments[astRef] || []).find( idHash => assignments.byId[idHash].address === address ); debug("id after global: %s", id); @@ -1232,14 +1232,14 @@ const data = createSelectorTree({ //if we're in a modifier, include modifierDepth if (inModifier) { id = stableKeccak256({ - idOrPath, + astRef, compilationId, stackframe: currentDepth, modifierDepth }); } else { id = stableKeccak256({ - idOrPath, + astRef, compilationId, stackframe: currentDepth });