4 Commits

Author SHA1 Message Date
Marc Schier 55bd944609 WoT: Types-side TD/TM-NodeSet conversion with consolidated corpus and minimal consumer compat (#4758)
# Description

Adds the pure Types-side WoT Thing Description / Thing Model to NodeSet
conversion: resolution, context, declarations, types, values,
localization, URI/format handling, bounded hashing, plus supporting
native XML codec, NodeSet alias/value helpers, RelativePathFormatter and
a JsonElement equality polyfill.

- Carrier-witness fix: a missing native event is accepted only when the
owning preserved type declares it through a `GeneratesEvent` reference
(directly or via its type/supertype chain) AND a bounded, validated
selected EventType carrier identity equals the normalized authored
native target. Native-present events get a full compare; an ambiguous
native key and a missing map stay strict; a readable document is never
archive authority.
- Support-only dependencies: additive per-instance, non-serialized
`WotDocument.IsSupportOnly(kind, name)` (ArgumentNullException guard).
The resolver marks support-only after closure; explicit selection wins;
the View builder excludes only true support-only members, so unit/actsOn
dependencies stay in the JSON. Nested controls cover inner value-only
projection under an outer value-only selection (unit kept, support-only)
versus an outer explicit SelectAll (explicit, not support-only).
- Documentation/XML comments and member-order only in commit 5c368d3a;
no logic change.
- Timeout repair on current head 6957dd46: invocation-scoped
`ArchiveDerivations` reuse removes repeated document-set derivation work
without a global cache (functional files
`WotNodeSetConverter.{Archive,ArchiveDerivations,Partitions,WoT}.cs`,
plus `WotArchiveDerivationsTests` and
`WotDocumentSetSharedValidationTests`). The original local full29
reproduction changed from 27 passed / 2 Refresh timeouts to 29 passed
with unchanged limits; official CI on this head FAILED at three
per-project time ceilings (see the evidence ledger). Temporary RF1
diagnostics were fully removed; the final tree differs from 0f7b9a09
only in the six functional files.
- Test-only net48 compile repair in commit b838907 (earlier head):
official CI on 5c368d3a was RED on the net48 build with CS1061 (see
ledger); the fix adds `using System.Threading;` and an unqualified
`CancellationTokenSource` in one test file. No production change.

Defaults: DI default document budget 256 versus the sample's explicit
1024. Corpus: canonical 540-JSON inventory; the actual manifest is 535
entries = 394 TD + 141 TM (the roles of the other 5 are not claimed).
Native Pumps assertions (9624 nodes / 339 partitions) are unchanged.
2026-10-17 20:43:25 +02:00
romanett 9b034f8291 Enable nullable reference types centrally; migrate all unset and annotations-only projects (#4700)
# Description

Nullable reference types are now enabled once, in `common.props`, and
every project in the repository builds warning-clean with them.

**Configuration**
- `<Nullable>enable</Nullable>` lives in `common.props`. All per-project
`<Nullable>` settings are removed: 178 project files (enable,
annotations, and the `disable` in the three Aot test projects).
- 419 per-file `#nullable enable`/`restore` directives and the 4
`#nullable disable` directives are removed.
- Kept on purpose:
- The 5 `<auto-generated>` schema files (`UANodeSet.cs`, `UA Type
Dictionary.cs`, `OPCBinarySchema.cs`, `SecuredApplication.cs`,
`PInvokeHelper.cs`) keep `#nullable enable`. The compiler ignores the
project setting in generated code, so the directive is required there.
- `tests/Opc.Ua.Interop.LegacyPeer` keeps `disable`. It builds against
the 1.5.378 packages and does not import the repository props.
- `docs/DeveloperGuide.md` and `.github/copilot-instructions.md` now
describe the central setting.

**Migration** (the 43 unset and 13 annotations-only projects, roughly
10k diagnostics)
- **Production code: annotated at the declarations.** Covers
`tools/Opc.Ua.SourceGeneration.Core`, `src/Opc.Ua.Lds.Server` and the
LDS sample.
- Members, parameters and returns are nullable where null actually
flows.
- Null-check helpers carry `[NotNullWhen]` (`IsNull`, `IsValidXmlName`,
`IsMethodTypeDesign`).
- `CoreUtils.Format`, `Utils.Format`, `ITemplateWriter.WriteLine` take
`params object?[]`. `Template.AddReplacement` takes `string?` (rendering
already skips null replacements).
- `IRegisteredServerStore.RegisterAsync` returns
`Task<RegistrationEntry?>`: it returns null when a registration is
removed.
- Dereferences backed by an invariant (for example, the validated model)
use `!`, so runtime behaviour is unchanged.
- **Behavioural changes in production code** (small, deliberate):
- `NodeSetToModelDesign` throws `InvalidOperationException` when the
file is not a NodeSet. Before, it threw a NullReferenceException on the
next line.
- `ModelDesignValidator` starts its lookup tables empty instead of null.
A redundant `if (m_nodes == null) return;` guard is gone.
- **Test code: minimal annotations.**
  - `?` on values that can be null, `!` where the test asserts non-null.
  - `= null!` for fixture members assigned in SetUp.
- `TryGetStructure<T>(out T? x)` where the inferred `T?` broke the
`IEncodeable` constraint.
- A few redundant `== null` checks on structs (`NodeId`, `ArrayOf<T>`)
folded into the adjacent `IsNull`/`Count` checks.

**Notes for reviewers**
- The diff is large (~1,500 files) but almost entirely mechanical: `?`,
`!` and directive removal. The non-annotation changes are listed above.
- Known follow-up, not done here:
`IModelDesign.Namespaces/TargetNamespace/NamespaceUris` stay
non-nullable even though the validator returns null before it loads a
dictionary. Making them nullable would ripple through every generator
call site.

## Related Issues

- Fixes #4439

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.

The "no new warnings" box covers net10.0 and net48: full non-incremental
builds of `UA.slnx`, `tools/SourceGeneration.slnx`,
`tools/MigrationAnalyzer.slnx` and the Aot test projects finished with 0
warnings and 0 errors under the repository's warnings-as-errors
settings. net9.0 and net8.0 also had no nullable diagnostics, but they
were not rebuilt after the final fixes. Tests have not been run locally
yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 08:48:13 +02:00
Marc Schier d08d4faec1 Reduce NodeState allocations and pack scalar Variants (#4452)
# Description

Consolidate the complete B01/B02 NodeState memory work into one PR.

- Replace eager cold-path NodeState locks with lazy canonical
publication and update
  the event-monitor counter atomically.
- Store six design-metadata properties and three security properties in
separate lazy
private bags while preserving public APIs, null/empty distinctions,
masks, copying
  and existing serialization behavior.
- Avoid allocating the ReportEvent scheduling closure when the
async-dispatch path is
  unused.
- Retain the logger factory's category logger directly, avoiding a
redundant typed
  wrapper on telemetry initialization.
- Keep Variant at 24 bytes while removing eligible outer boxes for
QualifiedName,
  NodeId, NET8+ ByteString and text-only LocalizedText values.
- Add reproducible allocation/layout/occupancy fixtures, real registered
and monitored
populations, reference contracts, generated-consumer coverage and
NativeAOT cases.

## Measured allocation changes

Matched .NET 10.0.11 x64 observations against the integrated master
baseline:

| Construction/assignment | Master | This PR |
|---|---:|---:|
| Bare/minimal object | 824 B | 640 B |
| Bare/minimal variable | 1160 B | 976 B |
| Variable with both optional groups populated or reset | 1160 B | 1088
B |
| Variable with a shared ByteString value | 1192 B | 976 B |

Separate paired measurements show:

- telemetry initialization: 24 B typed-logger wrapper removed;
- eligible QualifiedName, NodeId and ByteString Variant construction: 32
B to 0 B;
- eligible text-only LocalizedText Variant construction: 40 B to 0 B;
- variable attributes read into caller-provided Variant destinations:
136 B to 0 B.

These are runtime-specific per-operation observations, not additive
whole-server
savings. Optional bags retain their documented populated/high-water
premiums and are
not reclaimed on reset.

## Reference-storage decision

A complete private indexed reference backend and a sorted-traversal
alternative were
measured, but both changed the existing filtered hash-index enumeration
order. They
were rejected despite lower memory use. The production reference backend
remains
unchanged; strengthened ordering, identity, serialization and
concurrency contracts
are retained. Adaptive small-set storage remains deferred.

## Consolidation

This PR now contains all changes from #4451 and the former narrower
#4452 branch.
Every #4452 changed path was present in #4451; after merging, the #4451
head
`836e45226` is a direct ancestor of this branch. #4451 is closed as
superseded.
Draft #4425 remains unchanged and is also superseded by this
consolidated work.

## Review feedback

- Removed the standalone Variant storage document and its README entry.
- Made the raw NodeId constructor private; the documented internal
`GetRawState`/`SetRawState` bridge is explicitly Variant-only and must
never become
  public.
- Marked the two 32-thread counter tests non-parallel.
- Added 10-second timeouts to the concurrent browse benchmark's main and
worker
  barriers and completion waits.
- Migrated the registered-population fixture to the current async
`SealAsync` API.

All review threads on #4451 and #4452 were replied to with the action
and fix commit,
then resolved.

## Related issues

- Related to #4275.
- Supersedes #4425 and #4451.

## Validation

- Consolidated Types/Core/Server selection: **1241 passed** on net10.0.
- Consolidated Types/Core/Server selection: **1238 passed** on net48.
- Focused #4451 feedback selection: **189 passed** on net10.0 and **187
passed**
  on net48.
- Earlier integrated NativeAOT validation passed **163/163** cases
across the main,
MCP and Historian applications; current PR CI provides the authoritative
final
  merged-source native validation.

The first #4452 CI run was blocked by merge conflicts. Seven later jobs
completed
their tests but encountered a shared artifact-service HTTP 403 while
uploading
results; no workflow or test was weakened to mask that infrastructure
failure.

Generated `report.*.json` crash artifacts remain untracked and are not
part of this PR.

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove the changes and improve coverage.
- [x] I have added the necessary current-behavior documentation.
- [ ] I have verified that the fresh consolidated CI run introduces no
build or analyzer warnings.
- [ ] I ran the complete UA.slnx suite locally on net48 and net10.0 with
no failures.
- [ ] I fixed all failing and flaky CI tests and all CodeQL warnings.
- [x] I have addressed all PR feedback received.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d2569e2e-7115-4969-bb44-8159e302b450
2026-09-09 16:48:13 +02:00
Marc Schier 7cec2d614d Move repository files to the consolidated layout 2026-07-16 06:25:54 +02:00