[YANGTOOLS-1372] Add support for purely-effective substatements Created: 30/Nov/21  Updated: 26/Oct/23  Resolved: 16/Dec/21

Status: Resolved
Project: yangtools
Component/s: parser
Affects Version/s: None
Fix Version/s: 8.0.0

Type: New Feature Priority: High
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Issue Links:
Blocks
blocks YANGTOOLS-1338 Generate ietf-restconf operations lea... Resolved
blocks YANGTOOLS-1270 Instantiate EffectiveRevisionDate sta... Confirmed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
YANGTOOLS-1383 Do not emit UndeclaredCaseStatements Sub-task Resolved Robert Varga  
YANGTOOLS-1384 Remove ModelStatement.statementSource() Sub-task Resolved Robert Varga  

 Description   

StmtContext.Mutable does not expose the ability to conjure purely-effective statements, i.e. those which are truly inferred from overall context and do not have a DeclaredStatement counterpart.

There are two use cases: implicit input/output statements in RPCs and Actions, which we cover through a rather ugly hack called StatementContextBase.appendImplicitSubstatement(). That part does still ends up creating a DeclaredStatement and also does not cover ModelStatement.argument() completely – for example it does not work for YANGTOOLS-1338, where the argument is a QName and we do not have a way to create a rawArgument String which would parse to what we need because we do not have the corresponding imports. Final deficiency is that it creates a SubstatementContext, i.e. having weird ties to declaration site.

Expose a new method StmtContext.Mutable, which will create a truly effective-only statements. The argument should be an ImplicitStatementAwareSubstatementContext (or similar, as that is a mouthful), which is an additional interface implemented by things like InputStatementSupport and can work without a DeclaredStatement instance.



 Comments   
Comment by Robert Varga [ 12/Dec/21 ]

The current infra actually does something different – it is adding implicit statements, i.e. those still have a DeclaredStatement, but that declared statement shows up as being StatementOrigin.DECLARATION.

In the reactor this is implied by the use of SubstatementContext for these statements. In individual statements supports (which support this) it shows up as special-casing in createDeclared(). In yang-model-ri this manifests as ImplicitStatements – which end up recognized in factory methods and ignored.

This needs to work quite differently:

  1. we need an optional-to-implement UndeclaredStatementFactory, which will have an alternative createEffective() method, which does rely on DeclaredStatement
  2. we need an UndeclaredStmtCtx in the reactor, which will support Mutable.addEffectiveSubstatement(), with a better name of addUndeclaredSubstatement() – and there needs to be a checkArgument() to verify that the supplied support implements UndeclaredStatementFactory
  3. ImplicitStatements needs to be removed (along with the classes it references)
  4. We need to have an UndeclaredStatements to directly create EffectiveStatement instances
  5. Users of ImplicitStatements need to be migrated to implement UndeclaredStatementFactory

The be-all end-all reason is that we do not have a reliable raw argument String, required for DeclaredStatements. The other is quick consistency checks to an opt-in behaviour – i.e. RpcStatementSupport can only use implicit input statements because InputStatementSupport knows how to deal with them – and that capability is not exposed as a trait (such as UndeclaredStatementFactory ), it is just an implementation detail. The third, minor one, is that we create bogus objects to dance around StatementContextBase's requirement of having a DeclaredStatement instance.

Comment by Robert Varga [ 13/Dec/21 ]

Okay, this is a bit more complicated and boils down to ModelStatement.statementOrigin() and its interpretation in DeclaredStatement vs EffectiveStatement. Part of this is an implementation quirk of statement loading, where we end up inserting UndeclaredCaseStatement into DeclaredChoiceStatement:

choice foo {
   case bar;
   container baz;
}

ends up looking like this:

ChoiceStatement foo
  DeclaredCaseStatement bar
  UndeclaredCaseStatement baz
    Container baz

The difference between Declared and Undeclared CaseStatements is only statementOrigin(). We have to account for this in yang-model-export and inline StatementOrigin.CONTEXT statements' substatements.

We therefore need to perform a bit of house cleaning:

  1. eliminate generation of UndeclaredCaseStatement and instead inline Container baz, just as it is declared (YANGTOOLS-1383)
  2. move ModelStatement.statementOrigin() to EffectiveStatement, eliminating Undeclared* DeclaredStatements (YANGTOOLS-1384)

Once that is done, we can roll out proper specialized implementations.

Generated at Wed Feb 07 20:55:58 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.