42 Commits

Author SHA1 Message Date
Andrew McNulty
19922d70dc Misspellings: add closest match for object method names
If the user misspells an object method name then suggest the closest
match in the error message.
2026-06-12 12:06:28 +02:00
Dylan Baker
75b9a3287e mesonlib: Add a constant for the root SubProject
To avoid needing to cast or convert throughout the codebase.
2026-05-18 11:22:22 -07:00
Dylan Baker
b9ad8a0604 utils: Move SubProject definition to utils.universal
Since we use it at ever layer of the codebase, it doesn't make sense for
it to live in the interpreter
2026-05-18 11:22:22 -07:00
Paolo Bonzini
b24583b638 replace ABCMeta with SimpleABC
The virtual superclass feature of ABCMeta is never used by Meson.  Replace
it with SimpleABC, which results in a 3-4% speedup.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-05-01 06:39:46 +02:00
Paolo Bonzini
e0bb042ca0 interpreterbase: remove per-object method dispatching
Only support class-based dispatch, all objects have been
converted.
2025-06-17 12:29:56 +03:00
Paolo Bonzini
9b3932abb3 interpreter: make methods per-class for primitives
Do not call update() and Enum.__hash__ a gazillion times; operators
are the same for every instance of the class.  In order to access
the class, just mark the methods using a decorator and build
METHODS later using __init_subclass__.

Non-primitive objects are not converted yet to keep the patch small.
They are created a lot less than other objects, especially strings
and booleans.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17 12:29:56 +03:00
Paolo Bonzini
2f47d0b4b1 interpreter: make operators per-class
Do not call update() and Enum.__hash__ a gazillion times; operators
are the same for every instance of the class.  In order to access
the class for non-trivial operators, the operators are first marked
using a decorator, and then OPERATORS is built via __init_subclass__.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17 12:29:56 +03:00
Paolo Bonzini
f3366a7e54 interpreter: make trivial_operators per-class
Do not call update() and Enum.__hash__ a gazillion times; trivial
operators are the same for every instance of the class.

Introduce the infrastructure to build the MRO-resolved operators (so
the outcome same as if one called super().__init__) for each subclass
of InterpreterObject.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17 12:29:56 +03:00
Paolo Bonzini
992a93bcef interpreter: make operator functions binary
In preparation for moving them to the class, make the operator functions
binary.  Adjust the lambdas for trivial operators, and store unbound
methods for non-trivial ones.

Note that this requires adding operators manually for every override,
even subclasses.  It's decidedly ugly at this temporary stage; later
it will result in just an extra @InterpreterObject.operator decorator
on the subclasses.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17 12:29:56 +03:00
Volker Weißmann
4a57a5fd0c AstInterpreter: Fix dead-code-crash
Without this commit, the rewriter and the static introspection tool
crash if `meson.build` contains something like
```meson
if false
  foo = not_defined
endif
```
or
```meson
if false
  message(not_defined)
endif
```
While it could be argued, that you should not write stuff like this,
this used to raise a `MesonBugException`, which we have to fix.

Fixes #14667
2025-06-09 21:01:09 +03:00
Volker Weißmann
e8f27f5912 rewriter: Replace assignments with cur_assignments
Replace the variable tracking of `AstInterpreter.assignments`
with a slightly better variable tracking called
`AstInterpreter.cur_assignments`.
We now have a class `UnknownValue` for more explicit handling
of situations that are too complex/impossible.
2025-05-29 09:20:27 -07:00
Dylan Baker
f83dca32fe interpreterbase: Use explicit TypeAlias annotation to allow recursive types
And fix all of the issues that pop up once we remove the use of `Any`,
which hides so many problems.
2024-09-08 22:50:21 -04:00
Eli Schwartz
f2112d0baa Revert "Clarify mutable objects usage"
This reverts commit 9f02d0a3e5.

It turns out that this does introduce a behavioral change in existing
users of ConfigurationData, which it wasn't supposed to (it was supposed
to preserve behavior there, and add a new *warning* for
EnvironmentVariables).

This breaks projects such as pulseaudio, libvirt, and probably more.
Roll back the change and try again after 1.5.0 is released.

Fixes: #13372
2024-07-05 13:52:40 -04:00
Xavier Claessens
9f02d0a3e5 Clarify mutable objects usage
Only Environment and ConfigurationData are mutable. However, only
ConfigurationData becomes immutable after first use which is
inconsistent.

This deprecates modification after first use of Environment object and
clarify documentation.
2024-04-14 19:40:02 +03:00
Dylan Baker
e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Tristan Partin
88b337b77c Remove unused code in interpreterbase 2023-10-04 15:16:58 -04:00
Eli Schwartz
d4615369ff fix lint errors revealed by pycodestyle 2.11
When performing isinstance checks, an identity comparison is
automatically done, but we don't use isinstance here because we need
strict identity equality *without allowing subtypes*.

Comparing type() == type() is a value comparison, but could produce
effectively the same results as an identity comparison, usually, despite
being semantically off. pycodestyle learned to detect this and warn you
to do strict identity comparison.
2023-07-31 11:00:22 -07:00
Xavier Claessens
f0dc61a764 interpreter: Add testcase..endtestcase clause support
This is currently only enabled when running unit tests to facilitate
writing failing unit tests.

Fixes: #11394
2023-03-01 20:13:34 -05:00
Eli Schwartz
680b5ff819 treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz
e5c7dc199a typing: use forward reference for types defined later in file 2022-05-23 16:44:07 -04:00
Eli Schwartz
187dc656f4 merge various TYPE_CHECKING blocks into one
A bunch of files have several T.TYPE_CHECKING blocks that each do some
things which could just as well be done once, with a single `if`
statement. Make them do so.
2022-03-07 19:01:04 -05:00
Eli Schwartz
c0b8e02d9f FeatureNew: add mypy type annotations for subproject arg
Use a derived type when passing `subproject` around, so that mypy knows
it's actually a SubProject, not a str. This means that passing anything
other than a handle to the interpreter state's subproject attribute
becomes a type violation, specifically when the order of the *four*
different str arguments is typoed.
2022-02-14 20:40:41 -05:00
Eli Schwartz
8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Christian Clauss
a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Daniel Mensinger
dfec4385a7 interpreter: Move RangeHolder out of interpreterbase to interpreter 2021-10-06 22:37:18 +02:00
Daniel Mensinger
af0587cb49 interpreter: Holderify arrays and dicts
This is the final refactoring for extracting the bultin object
logic out of Interpreterbase. I decided to do both arrays and
dicts in one go since splitting it would have been a lot more
confusing.
2021-10-06 22:37:18 +02:00
Eli Schwartz
4ab70c5512 fix extra whitespace
discovered via flake8 --select E303
2021-10-04 16:29:31 -04:00
Daniel Mensinger
6b00c7dc81 Remove helpers.check_stringlist() 2021-09-25 12:44:11 +02:00
Daniel Mensinger
d93d01b6c5 interpreter: Introduce StringHolder
Another commit in my quest to rid InterpreterBase from all higher
level object processing logic.

Additionally, there is a a logic change here, since `str.join` now
uses varargs and can now accept more than one argument (and supports
list flattening).
2021-09-25 12:44:11 +02:00
Daniel Mensinger
43302d3296 interpreter: Introduce BooleanHolder for the bool primitive 2021-09-01 19:17:01 +02:00
Daniel Mensinger
8d92e6d865 interpreter: Add IntegerHolder 2021-08-31 23:01:21 +02:00
Daniel Mensinger
86f70c873a interpreter: Introduce operators support for InterpreterObjects 2021-08-31 23:01:21 +02:00
Dylan Baker
580f316043 interperterbase: help type checkers do better type deduction
This assert causes several type checkers (both mypy and pyright) to
force `obj` to be a base `HoldableObject` instead of the specialized
object. Since the check itself may still be valuable as we don't have
fully type annotation coverage it's simply been removed when type
checking to aid in type specialization.
2021-08-16 16:21:51 -07:00
Xavier Claessens
0183954ea1 Fix meson.version().version_compare() regression in subproject 2021-07-21 13:33:06 -04:00
Daniel Mensinger
8f7343831b refactor: Refactor BothLibraries logic
This commit introduces a new type of `HoldableObject`: The
`SecondLevelHolder`. The primary purpose of this class is
to handle cases where two (or more) `HoldableObject`s are
stored at the same time (with one default object). The
best (and currently only) example here is the `BothLibraries`
class.
2021-06-26 12:49:35 +02:00
Daniel Mensinger
5cd9f88d6c fix: Ensure that build targets have all methods from ExternalProgram
As a side-effect from #8885 `find_program()` returns now `Executable`
objects when `meson.override_find_program` is called with an
executable target. To resolve this conflict the missing methods
from `ExternalProgram` are added to `BuildTarget`.
2021-06-21 20:19:06 +03:00
Daniel Mensinger
66b32a4591 holders: Introduce HoldableObject 2021-06-18 23:48:33 +02:00
Daniel Mensinger
7be172fe16 interpreter: Meson does not have floats --> remove them 2021-06-18 23:48:33 +02:00
Daniel Mensinger
63ade7d937 interpreter: Add a new MesonInterpreterObject for non-elementary objects 2021-06-18 23:48:33 +02:00
Daniel Mensinger
202e345dfb interpreter: Refactor interpreter.compiler to use ObjectHolder 2021-06-18 23:48:33 +02:00
Daniel Mensinger
2b09af834a interpreter: Refactor ObjectHolder to extend InterpreterObject 2021-06-18 23:48:33 +02:00
Daniel Mensinger
687eebee29 interpreter: Split base objects and helpers from interpreterbase.py 2021-06-11 10:42:18 +02:00