Skip to content

registry

Classes:

Functions:

RuntimeFeatureRegistry

RuntimeFeatureRegistry()

Methods:

Source code in src/irx/runtime/registry.py
28
29
30
31
32
def __init__(self) -> None:
    """
    title: Initialize RuntimeFeatureRegistry.
    """
    self._features: dict[str, RuntimeFeature] = {}

get

get(name: str) -> RuntimeFeature
Source code in src/irx/runtime/registry.py
47
48
49
50
51
52
53
54
55
56
57
58
59
def get(self, name: str) -> RuntimeFeature:
    """
    title: Return a runtime feature by name.
    parameters:
      name:
        type: str
    returns:
      type: RuntimeFeature
    """
    try:
        return self._features[name]
    except KeyError as exc:
        raise KeyError(f"Unknown runtime feature '{name}'") from exc

names

names() -> tuple[str, ...]
Source code in src/irx/runtime/registry.py
61
62
63
64
65
66
67
def names(self) -> tuple[str, ...]:
    """
    title: Return the registered runtime feature names.
    returns:
      type: tuple[str, Ellipsis]
    """
    return tuple(sorted(self._features))

register

register(feature: RuntimeFeature) -> None
Source code in src/irx/runtime/registry.py
34
35
36
37
38
39
40
41
42
43
44
45
def register(self, feature: RuntimeFeature) -> None:
    """
    title: Register a runtime feature by name.
    parameters:
      feature:
        type: RuntimeFeature
    """
    if feature.name in self._features:
        raise ValueError(
            f"Runtime feature '{feature.name}' already exists"
        )
    self._features[feature.name] = feature

RuntimeFeatureState

RuntimeFeatureState(
    owner: "VisitorProtocol",
    registry: RuntimeFeatureRegistry,
    active_features: Iterable[str] | None = None,
)

Methods:

Source code in src/irx/runtime/registry.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def __init__(
    self,
    owner: "VisitorProtocol",
    registry: RuntimeFeatureRegistry,
    active_features: Iterable[str] | None = None,
) -> None:
    """
    title: Initialize RuntimeFeatureState.
    parameters:
      owner:
        type: VisitorProtocol
      registry:
        type: RuntimeFeatureRegistry
      active_features:
        type: Iterable[str] | None
    """
    self._owner = owner
    self._registry = registry
    self._active_features: set[str] = set()
    self._declared_symbols: dict[tuple[str, str], ir.Function] = {}

    if active_features is None:
        return

    for feature_name in active_features:
        self.activate(feature_name)

activate

activate(feature_name: str) -> None
Source code in src/irx/runtime/registry.py
116
117
118
119
120
121
122
123
124
def activate(self, feature_name: str) -> None:
    """
    title: Activate a runtime feature for the current module.
    parameters:
      feature_name:
        type: str
    """
    self._registry.get(feature_name)
    self._active_features.add(feature_name)

active_feature_names

active_feature_names() -> tuple[str, ...]
Source code in src/irx/runtime/registry.py
137
138
139
140
141
142
143
def active_feature_names(self) -> tuple[str, ...]:
    """
    title: Return the active feature names.
    returns:
      type: tuple[str, Ellipsis]
    """
    return tuple(sorted(self._active_features))

feature

feature(feature_name: str) -> RuntimeFeature
Source code in src/irx/runtime/registry.py
145
146
147
148
149
150
151
152
153
154
def feature(self, feature_name: str) -> RuntimeFeature:
    """
    title: Return a registered feature by name.
    parameters:
      feature_name:
        type: str
    returns:
      type: RuntimeFeature
    """
    return self._registry.get(feature_name)

is_active

is_active(feature_name: str) -> bool
Source code in src/irx/runtime/registry.py
126
127
128
129
130
131
132
133
134
135
def is_active(self, feature_name: str) -> bool:
    """
    title: Return whether a feature is active for the current module.
    parameters:
      feature_name:
        type: str
    returns:
      type: bool
    """
    return feature_name in self._active_features

linker_flags

linker_flags() -> tuple[str, ...]
Source code in src/irx/runtime/registry.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
def linker_flags(self) -> tuple[str, ...]:
    """
    title: Return the linker flags required by active features.
    returns:
      type: tuple[str, Ellipsis]
    """
    flags: list[str] = []
    seen: set[str] = set()

    for feature_name in self.active_feature_names():
        feature = self.feature(feature_name)
        for flag in feature.linker_flags:
            if flag in seen:
                continue
            seen.add(flag)
            flags.append(flag)

    return tuple(flags)

native_artifacts

native_artifacts() -> tuple[NativeArtifact, ...]
Source code in src/irx/runtime/registry.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
def native_artifacts(self) -> tuple[NativeArtifact, ...]:
    """
    title: Return the native artifacts required by active features.
    returns:
      type: tuple[NativeArtifact, Ellipsis]
    """
    artifacts: list[NativeArtifact] = []
    seen: set[tuple[str, str]] = set()

    for feature_name in self.active_feature_names():
        feature = self.feature(feature_name)
        for artifact in feature.artifacts:
            dedupe_key = (artifact.kind, str(artifact.path))
            if dedupe_key in seen:
                continue
            seen.add(dedupe_key)
            artifacts.append(artifact)

    return tuple(artifacts)

require_symbol

require_symbol(
    feature_name: str, symbol_name: str
) -> Function
Source code in src/irx/runtime/registry.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def require_symbol(
    self,
    feature_name: str,
    symbol_name: str,
) -> ir.Function:
    """
    title: Activate a feature and declare one of its external symbols.
    parameters:
      feature_name:
        type: str
      symbol_name:
        type: str
    returns:
      type: ir.Function
    """
    self.activate(feature_name)
    cache_key = (feature_name, symbol_name)
    cached = self._declared_symbols.get(cache_key)
    if cached is not None:
        return cached

    feature = self.feature(feature_name)
    try:
        symbol_spec = feature.symbols[symbol_name]
    except KeyError as exc:
        raise KeyError(
            f"Runtime feature '{feature_name}' does not declare "
            f"symbol '{symbol_name}'"
        ) from exc

    declared = symbol_spec.declare(self._owner)
    self._declared_symbols[cache_key] = declared
    return declared

get_default_runtime_feature_registry cached

get_default_runtime_feature_registry() -> (
    RuntimeFeatureRegistry
)
Source code in src/irx/runtime/registry.py
230
231
232
233
234
235
236
237
238
239
240
@lru_cache(maxsize=1)
def get_default_runtime_feature_registry() -> RuntimeFeatureRegistry:
    """
    title: Build the default runtime feature registry.
    returns:
      type: RuntimeFeatureRegistry
    """
    registry = RuntimeFeatureRegistry()
    registry.register(build_libc_runtime_feature())
    registry.register(build_arrow_runtime_feature())
    return registry