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

Feat(optim)!: rewrite of the constant folding pass #35

Merged
merged 54 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
96faf59
fix: try to use the new `contexte` mechanism
Clemog Jan 3, 2024
b27100f
fix: set parent to each rule in rules set
Clemog Jan 3, 2024
bbebc76
fix: add traversedVariables option
Clemog Jan 3, 2024
185aae8
fix: set parent to each rule in rules set again
Clemog Jan 3, 2024
1ddd2b4
fix: `nom` is not an attribute anymore
Clemog Jan 5, 2024
074ed79
feat: try to set a list of `contextRules`
Clemog Jan 5, 2024
964f58a
fix: an empty rule length is now 0
Clemog Jan 5, 2024
d35adfd
fix: add ruleName that includes context on contextRules
Clemog Jan 5, 2024
3c3ea5f
feat: add rules into context to contextRules
Clemog Jan 5, 2024
46e976a
Revert "feat: add rules into context to contextRules"
Clemog Jan 5, 2024
883cbf0
fix(optim): retrieve all rules impacted by a contexte mechanism
EmileRolley Jan 8, 2024
2aad8c1
wip: manage new contexte
EmileRolley Jan 8, 2024
e446b37
fix(optim): over-fold rules that could be impacted by a contexte
EmileRolley Jan 8, 2024
d38cda2
refactor(optim): remove the use of traversedVariables only use refs.c…
EmileRolley Jan 9, 2024
444e738
perf(optim): replace isInParsedRules with inline 'ruleName in ctx.par…
EmileRolley Dec 19, 2023
2c60468
perf(optim): simplify the removeRuleFromRefs
EmileRolley Dec 19, 2023
3c8ea5e
perf(optim): don't return ctx as it's already mutated in place
EmileRolley Dec 19, 2023
4447437
refactor(optim): use serializeEvaluation from publicodes instead of t…
EmileRolley Dec 19, 2023
ddb7bb0
refactor(optim): start to implement serializeParsedRules
EmileRolley Dec 19, 2023
e0e1216
pkg: upgrade publicodes to rc.6
EmileRolley Jan 8, 2024
78d6309
fix: upgrade to rc.7
EmileRolley Jan 15, 2024
160bd31
refactor(optim): serializedParsedRules implemented and tested against…
EmileRolley Jan 15, 2024
2dc05a8
refactor(optim): fix the 'unité' serialization
EmileRolley Jan 17, 2024
6000bb9
refactor(optim): serialization implemented of all the basic API
EmileRolley Jan 17, 2024
ca5454b
refactor(optim): add the missing 'grille' mecanism for serialization
EmileRolley Jan 17, 2024
dc027ff
fix(optim): 'nom' doesn't exist in 'rawNode' anymore
EmileRolley Jan 17, 2024
08d018e
nitpick(opti): unify comment format
EmileRolley Jan 17, 2024
e1248c3
refactor(test/optim): set allowOrphanRules to true for the engine
EmileRolley Jan 18, 2024
0993335
feat(optim): regression tests pass for the new optim
EmileRolley Jan 18, 2024
eae3979
refactor(optim): remove unused code
EmileRolley Jan 18, 2024
896962f
fix(optim): fold contextes evaluated as constants
EmileRolley Jan 22, 2024
e536489
test(optim): uncomment tests on [applicable si] etc...
EmileRolley Jan 22, 2024
117f485
perf(optim): use Set instead of Array in RefMap
EmileRolley Jan 22, 2024
2be276e
fix(optim): use 'fully' and 'partially' marks
EmileRolley Jan 22, 2024
08adb09
fix(optim): manage null values
EmileRolley Jan 22, 2024
1d38f2d
nitpick(optim): clean
EmileRolley Jan 22, 2024
4e5fe75
fix(optim): don't fold nullable rules
EmileRolley Jan 25, 2024
bcdd9ee
fix(optim): correctly substitute constant value
EmileRolley Jan 25, 2024
3885063
fix: serialize the [remplacement] mecanism
EmileRolley Jan 25, 2024
911d1f4
fix: serialize the [inversion] mecanism
EmileRolley Jan 25, 2024
f26243a
feat: serialize the [résoudre la référence circulaire]
EmileRolley Jan 25, 2024
e3eb4f0
fix(optim): don't fold remplacement rules
EmileRolley Feb 1, 2024
cc5775e
fix: serialize private rules
EmileRolley Feb 1, 2024
599d785
fix: removed syntaxic sugar from raw node in serialization
EmileRolley Feb 1, 2024
f4f9f29
fix(optim): manage private rules
EmileRolley Feb 1, 2024
0fbfe15
fix(optim): correctly mark rules as fully optimized
EmileRolley Feb 2, 2024
2fd6b88
feat(optim): correctly substitute ref
EmileRolley Feb 2, 2024
508bdb1
nitpick: factorize [barème] serialization
EmileRolley Feb 2, 2024
8c49e9f
pkg: constrain the node version
EmileRolley Feb 2, 2024
c9e2676
test: change 'toStrictEqual' to 'toEqual' due to the use of 'structur…
EmileRolley Feb 2, 2024
7ae9db1
fix(optim): better handling of contexte rules
EmileRolley Feb 2, 2024
46e9cb1
fix(ci): remove the fixed node version
EmileRolley Feb 2, 2024
a2a0d54
pkg: upgrade to [email protected]
EmileRolley Feb 12, 2024
a881cda
nitpick: format
EmileRolley Feb 12, 2024
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: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
- run: yarn install --immutable

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"engines": {
"node": ">=17"
},
"exports": {
".": {
"import": "./dist/index.js",
Expand Down Expand Up @@ -47,16 +50,15 @@
"license": "MIT",
"dependencies": {
"@types/node": "^18.11.18",
"publicodes": "1.0.0-beta.77"
"publicodes": "^1.0.1"
},
"devDependencies": {
"@types/jest": "^29.2.5",
"docdash": "^2.0.1",
"jest": "^29.4.1",
"mitata": "^0.1.6",
"prettier": "^3.0.0",
"ts-jest": "^29.0.4",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"tsup": "^6.5.0",
"typedoc": "^0.24.8",
"typedoc-plugin-export-functions": "^1.0.0",
Expand Down
40 changes: 3 additions & 37 deletions source/commons.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { basename } from 'path'
import {
Rule,
ParsedRules,
Logger,
ExprAST,
RuleNode,
reduceAST,
ASTNode,
} from 'publicodes'
import { Rule, Logger, ExprAST, reduceAST, ASTNode } from 'publicodes'
import yaml from 'yaml'

/**
Expand Down Expand Up @@ -67,39 +59,13 @@ export type ImportMacro = {
/**
* Represents a non-parsed NGC rule.
*/
export type RawRule = Omit<Rule, 'nom'> & ImportMacro
export type RawRule = Omit<Rule, 'nom'> | ImportMacro

/**
* Represents a non-parsed NGC model.
*/
export type RawRules = Record<RuleName, RawRule>

/**
* Returns the raw nodes of a parsed rules object.
*
* @param parsedRules - The parsed rules object.
*
* @returns The raw nodes of the parsed rules object.
*/
export function getRawNodes(parsedRules: ParsedRules<RuleName>): RawRules {
return Object.fromEntries(
Object.values(parsedRules).reduce((acc, rule) => {
const { nom, ...rawNode } = rule.rawNode
// We don't want to keep the `avec` attribute in the raw node
// as they are already resolved in the [parsedRules] object.
delete rawNode['avec']

acc.push([
rule.dottedName,
// If the rule only contained the 'nom' attribute, we don't want to
// keep an empty object in the raw node.
Object.keys(rawNode).length === 0 ? null : rawNode,
])
return acc
}, []),
) as RawRules
}

function consumeMsg(_: string): void {}

export const disabledLogger: Logger = {
Expand All @@ -115,7 +81,7 @@ export const disabledLogger: Logger = {
*
* @returns The references.
*/
export function getAllRefsInNode(node: RuleNode): RuleName[] {
export function getAllRefsInNode(node: ASTNode): RuleName[] {
return reduceAST<RuleName[]>(
(refs: RuleName[], node: ASTNode) => {
if (node === undefined) {
Expand Down
22 changes: 2 additions & 20 deletions source/compilation/resolveImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,6 @@ ${importedRule.description}`
}
}

/**
* @throws {Error} If the `nom` attribute is different from the `ruleNameToCheck`.
*/
function removeRawNodeNom(
rawNode: Rule,
ruleNameToCheck: string,
): Omit<Rule, 'nom'> {
const { nom, ...rest } = rawNode
if (nom !== ruleNameToCheck)
throw Error(
`Imported rule's publicode raw node "nom" attribute is different from the resolveImport script ruleName. Please investigate`,
)
return rest
}

function appearsMoreThanOnce(
rulesToImport: RuleToImport[],
ruleName: RuleName,
Expand Down Expand Up @@ -218,7 +203,7 @@ export function resolveImports(
let neededNamespaces = new Set<string>()
const resolvedRules = Object.entries(rules).reduce((acc, [name, value]) => {
if (name === IMPORT_KEYWORD) {
const importMacro: ImportMacro = value
const importMacro = value as ImportMacro
const engine = getEngine(filePath, importMacro, verbose)
const rulesToImport: RuleToImport[] =
importMacro['les règles']?.map(getRuleToImportInfos)
Expand Down Expand Up @@ -252,10 +237,7 @@ export function resolveImports(
utils
.ruleParents(ruleName)
.forEach((rule) => neededNamespaces.add(`${namespace} . ${rule}`))
return [
`${namespace} . ${ruleName}`,
removeRawNodeNom(ruleWithUpdatedDescription, ruleName),
]
return [`${namespace} . ${ruleName}`, ruleWithUpdatedDescription]
}

const ruleWithOverridenAttributes = { ...rule.rawNode, ...attrs }
Expand Down
1 change: 1 addition & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './commons'
export * from './serializeParsedRules'
Loading
Loading