Merge pull request #3176 from DeusData/feat/dart-path-rule

feat(pipeline): resolve Dart import URIs in the path rule
This commit is contained in:
Martin Vogel
2026-12-04 21:19:03 +01:00
committed by GitHub
4 changed files with 4795 additions and 52 deletions
File diff suppressed because it is too large Load Diff
+141 -12
View File
@@ -21,12 +21,68 @@
* paths from the directory it runs in). A guess decides no IMPORTS edge (main
* decides) and resolves no include of the shared layer.
*
* Dart reads a URI, not a path, as the Dart SDK 3.14.1 resolves it (each
* case checked with `dart pub get`, `dart analyze` and `dart run`), with one
* exception by the project's decision: a version constraint on the
* repository's one package of that name takes that package, as the working
* setup does, where the SDK on the committed files takes the published copy.
* `package:<name>/<path>` names <path> under the lib/ of
* the package <name> stands for in the importer's resolution: the importer's
* package is the nearest indexed pubspec.yaml at or above it; its resolution
* (a workspace member's: its workspace's) holds the package itself and the
* workspace members, an override of the name (it counts when nothing depends
* on it), then the dependencies and dev_dependencies of those packages and
* the dependencies of every path dependency reached. pub takes one source per
* name for the whole closure: two sources at any depth leave the name
* undecided, two known ones make pub refuse the resolution (every package:
* answer of the root undecided), and an unread or unplaceable closure leaves
* the root's package: answers undecided too (a readable closure is the
* condition for any of them); an override replaces a dependency's source, and
* the dependency_overrides of a pubspec_overrides.yaml beside the pubspec
* replace the pubspec's own (a file without that key leaves them). A path
* dependency names the directory it states. A version constraint on a name
* exactly one indexed pubspec carries is that package (the working setup);
* git, a hosted URL, the SDK, and a version with two namesakes are undecided,
* with none no file. A name no level lists is one dart cannot
* resolve, or one reached only through a package outside the repository (no
* file). Undecided as well: two sources of one name at one level, a path
* dependency the rule cannot follow. `dart:` names a library of the SDK. Any
* other URI is relative to the importing library: a file under its package's
* lib/ is the library package:<name>/..., so the URI stays in lib/ (`..` above
* it is dropped); any other file resolves on disk. A URI path ending in `/`
* names a directory (no file). The pubspecs are read once, when the universe
* is built, from the indexed pubspec.yaml files themselves, by the rule's own
* line reader, a whitelist: at the root a line is blank, a comment or a plain
* key (letters, digits, underscore, then a colon), and any other root line
* makes the pubspec unread; inside the sections it takes, an entry twice, a
* key of an entry twice, a scalar entry with a deeper line or a form it does
* not take makes it unread too. An unread pubspec makes that package's
* resolution undecided. It reads CRLF line ends and a quoted key without an
* escape (dart reads them), skips block scalars whole, and reads `key :` as
* key. A Dart manifest that cannot be read at all makes every Dart answer
* undecided (the Protobuf and Make answers read none). A workspace member
* outside its workspace's directory makes that workspace unread (pub refuses
* it), so a member's workspace is never one of two listings.
* The file a Dart URI names is one exact listed path: a node found by name is
* no proof (lib/a.b.dart and lib/a/b.dart share one File node name), a file
* of another letter case is not it (dart on a case-sensitive file system
* rejects the import), and no other indexed path takes part in the answer, so
* deleting a Dart file changes only the imports that named it (the closure
* repair re-resolves those, through their edges into it). The incremental key
* therefore holds the pubspecs, not the Dart files; an edited pubspec declines
* the closure repair.
*
* Lifted from the parked include-scope branch (round 5, include_scope.c
* section 2): its bases, exactly-one, tail index and import node; the shell
* and Make evaluated paths and run directories stay there.
*
* Threads: a universe is built once, from the file list, before any question,
* and is read-only afterwards: a question writes nothing (sealed at creation).
* Threads: a universe is built once, from the file list (and the indexed
* pubspec.yaml files), before any question. A Dart root's name table is made
* on that root's first question, by one walk over its closure, and kept,
* under the universe's lock (the walk marks shared packages and allocates
* from the universe's arena); every later question of the root is one lookup
* under that lock. Nothing else is written after the build. The answers do
* not depend on the order of the questions.
*/
#include "cbm.h"
@@ -43,6 +99,14 @@ typedef struct {
CBMLanguage lang;
const char *const *suffixes; /* file names the listing keeps: ending in one of these */
const char *const *prefixes; /* ... or starting with one of these */
/* ... or named exactly one of these: a file whose content decides where
* the row's imports point (Dart: pubspec.yaml, whose name, dependencies
* and workspace place a `package:` URI, and pubspec_overrides.yaml, whose
* dependency_overrides replace the pubspec's) */
const char *const *root_names;
/* a Dart URI (`package:`, `dart:`, else relative to the importing file)
* instead of the bases and tail below */
bool dart_uri;
/* an import whose path does not end in one of `suffixes` is not a path
* the rule reads (Protobuf: a row that names no `.proto` file) */
bool path_needs_suffix;
@@ -61,11 +125,23 @@ const cbm_include_path_row_t *cbm_include_path_row(CBMLanguage lang);
/* True for a file name the listing keeps (a name some row's import can name). */
bool cbm_include_path_listed_name(const char *name);
/* True for an indexed path whose content decides where a row's imports point
* (a root name: pubspec.yaml, pubspec_overrides.yaml). An edit of such a file
* changes which file an import of an unchanged file names. */
bool cbm_include_path_root_file(const char *rel);
typedef struct cbm_include_universe cbm_include_universe_t;
/* The universe of the run's indexed files (`files`, the discovered list of
* the run on every route): every file whose name a row's import can name.
* Built here, read-only afterwards. NULL on allocation failure. */
* the run on every route): every file whose name a row's import can name, and
* the package of every indexed pubspec.yaml (read from `files[i].path`).
* NULL on allocation failure; a table insert that fails leaves a universe
* whose every answer is NONE, a Dart manifest that cannot be read one whose
* every Dart answer is NONE. Building costs the files' path segments and the
* pubspecs' lines. A Dart root costs its closure (the packages and entries
* its walk reaches) once, on its first question; each question one lookup.
* Roots that share a subgraph each walk it: r roots over h shared packages
* cost r times h (stated, not capped). */
cbm_include_universe_t *cbm_include_universe_new(const cbm_file_info_t *files, int count);
void cbm_include_universe_free(cbm_include_universe_t *u);
@@ -78,7 +154,9 @@ typedef enum {
CBM_INCLUDE_PATH_FILE, /* names one indexed file (path in the buffer) */
CBM_INCLUDE_PATH_NONE, /* a path whose file the rule cannot tell (several, unknown) */
/* No indexed file can be selected: the path is absent, or the CFML
* mapping rule has no unique match. */
* mapping rule has no unique match; Dart: the one path the URI names is
* not indexed, or the URI names an SDK library or a package outside the
* repository */
CBM_INCLUDE_PATH_NO_FILE,
/* a file picked by an assumption the index cannot check (path in the
* buffer): the include root or the directory make runs in. Not FILE: main
@@ -95,12 +173,58 @@ cbm_include_path_verdict_t cbm_include_path_resolve(const cbm_include_universe_t
const char *rel, CBMLanguage lang,
const CBMImport *imp, char *buf, size_t buf_sz);
/* Which package a `package:` URI of the file `rel` names, by the source the
* importer's resolution gives the name (include_path.h, Dart). */
typedef enum {
CBM_INCLUDE_DART_SELF = 0, /* (i) the importer's own package: exact */
/* (ii) a path dependency (dev, override): exact; also a version
* constraint on the repository's one package of that name, whose
* directory the resolution takes as the source, as for a path */
CBM_INCLUDE_DART_PATH,
CBM_INCLUDE_DART_TRANSITIVE, /* (ii) the same, a dependency of a path dependency: exact */
CBM_INCLUDE_DART_MEMBER, /* (iii) a member of the importer's workspace: exact */
/* (iv) a version constraint the rule does not answer: undecided with two
* or more namesakes or a pubspec it could not name, no file with none */
CBM_INCLUDE_DART_PLAIN,
CBM_INCLUDE_DART_EXTERNAL, /* (v) git, a hosted URL, the SDK: as (iv) */
CBM_INCLUDE_DART_UNLISTED, /* (vi) not in the resolution: no file (undecided when not whole) */
CBM_INCLUDE_DART_UNDECIDED, /* no package, a form not read, two sources */
} cbm_include_dart_class_t;
cbm_include_dart_class_t cbm_include_path_dart_class(const cbm_include_universe_t *u,
const char *rel, const char *uri);
#if defined(CBM_MEM_TEST_API) && CBM_MEM_TEST_API
/* Test-only, current thread: the nth table insert from now on fails as a
* failed allocation would (1 = the next one); reset disarms and returns
* whether it fired. */
void cbm_include_path_test_fail_insert(int nth);
bool cbm_include_path_test_reset_insert_failure(void);
/* Test-only, current thread: the nth manifest read from now on fails as an
* unreadable file or a failed allocation would; reset disarms and returns
* whether it fired. */
void cbm_include_path_test_fail_read(int nth);
bool cbm_include_path_test_reset_read_failure(void);
/* Test-only: the steps this thread's rule has counted (building a universe,
* answering), for growth tests. */
uint64_t cbm_include_path_test_steps(void);
/* Test-only, current thread: the nth answer array a finished Dart walk makes
* from now on fails as a failed allocation would; reset disarms and returns
* whether it fired. */
void cbm_include_path_test_fail_answers(int nth);
bool cbm_include_path_test_reset_answers_failure(void);
/* Test-only: the answer-array slots this thread has examined (putting an
* answer, looking one up), for growth tests that must see collisions. */
uint64_t cbm_include_path_test_probes(void);
#endif
/* The IMPORTS target of an import, for resolve_import_strategies: true when
* the path rule decides it, with *out the target node (the file's Module node
* when it has one, else its File node) or NULL: no edge (the named file has no
* node, or no indexed file is named; a symbol is never the target of a
* statement that names a file). False: main's strategies propose a target (a
* guess is not a decision), which cbm_include_path_accepts judges. */
* node, or no indexed file is named; the rule never decides a symbol as the
* target of a statement that names a file). False: main's strategies propose
* a target (a guess is not a decision), which cbm_include_path_accepts
* judges. */
bool cbm_include_path_decides(const cbm_pipeline_ctx_t *ctx, const char *rel, CBMLanguage lang,
const CBMImport *imp, const cbm_gbuf_node_t **out);
@@ -111,15 +235,20 @@ bool cbm_include_path_decides(const cbm_pipeline_ctx_t *ctx, const char *rel, CB
* own candidates (the path from the importer's directory or the root, `.` and
* `..` folded). The bytes are compared exactly: a file of another letter case
* names the file on a case-insensitive disk only, so it stays no edge. False:
* no edge (the dotted name strategies would reach a/b.mk for `a.b.mk`). True
* no edge (the dotted name strategies would reach a/b.mk for `a.b.mk`). The
* Dart row: only a File or Module node of the one file a relative URI means
* (against the importer's directory as the rule reads it, no tail, no root
* candidate); nothing for a `package:` URI the rule does not decide. True
* for any other language, for CFML (a template is always decided; any other
* CFML import is no path) and for no target. */
bool cbm_include_path_accepts(const cbm_pipeline_ctx_t *ctx, const char *rel, CBMLanguage lang,
const CBMImport *imp, const cbm_gbuf_node_t *target);
/* The semantic-manifest key of the universe: every indexed path a row's
* import can name, sorted, hashed. Reads the list only (no disk). Returns 0,
* or -1 on allocation failure. */
/* The semantic-manifest key of the universe: every indexed path whose set
* decides answers for other paths (a name the Protobuf and Make rows keep, and
* every pubspec.yaml; not a Dart file; every path when the repository holds a
* CFML file, since a template may name any file), sorted, hashed. Reads the
* list only (no disk). Returns 0, or -1 on allocation failure. */
int cbm_include_path_inventory_digest(const cbm_file_info_t *files, int count,
char out[CBM_SHA256_HEX_LEN + 1]);
+7
View File
@@ -3497,6 +3497,13 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
decline = "new_file";
goto done;
}
if (cbm_include_path_root_file(fresh[i].rel_path)) {
/* a pubspec.yaml or pubspec_overrides.yaml: what it declares
* decides which file a `package:` import of an unchanged Dart
* file names (include_path.h) */
decline = "include_root_changed";
goto done;
}
changed_paths[n_changed++] = (char *)fresh[i].rel_path;
continue;
}
File diff suppressed because it is too large Load Diff