Invocation: runtime error checks for auto-wiring

Since it would in fact be possible to access and write beyond the configured storage,
simply by using the builder API without considering consistency,
it seems advisable to use explicit runtime checks here, instead of
only assertions, and to throw an exception when violating bounds.

Moreover, unsuccessfully attempted to better arrange the functionality
between PortBuilder and WeavingBuilder; seemingly we have an rather tight
coupling here, and also the expectations regarding the processing function
seem to be too tight (but that's the reason why it's an prototype...)
This commit is contained in:
Fischlurch 2024-10-26 03:03:11 +02:00
parent d91d0b5926
commit c29c10fd62
3 changed files with 77 additions and 46 deletions

View file

@ -100,6 +100,7 @@
#define STEAM_ENGINE_WEAVING_PATTERN_BUILDER_H
//#include "steam/common.hpp"
#include "lib/error.hpp"
//#include "steam/engine/channel-descriptor.hpp"
//#include "vault/gear/job.h"
#include "lib/several-builder.hpp"
@ -107,7 +108,8 @@
#include "steam/engine/engine-ctx.hpp"
#include "steam/engine/buffer-provider.hpp"
#include "steam/engine/buffhandle-attach.hpp" /////////////////OOO why do we need to include this? we need the accessAs<TY>() template function
#include "lib/test/test-helper.hpp"
#include "lib/test/test-helper.hpp" ////////////////////////////OOO TODO added for test
#include "lib/format-string.hpp"
//#include "lib/util-foreach.hpp"
//#include "lib/iter-adapter.hpp"
//#include "lib/meta/function.hpp"
@ -122,10 +124,12 @@
namespace steam {
namespace engine {
namespace err = lumiera::error;
using std::forward;
using lib::Several;
using lib::Depend;
using util::_Fmt;
using util::max;
@ -357,6 +361,9 @@ namespace engine {
using FunSpec = _ProcFun<FUN>;
using TurnoutWeaving = Turnout<SimpleDirectInvoke<N,FUN>>;
static constexpr SizMark<sizeof(TurnoutWeaving)> sizMark{};
static constexpr uint FAN_I = FunSpec::FAN_I;
static constexpr uint FAN_O = FunSpec::FAN_O;
using TypeMarker = std::function<BuffDescr(BufferProvider&)>;
using ProviderRef = std::reference_wrapper<BufferProvider>;
@ -380,9 +387,13 @@ namespace engine {
WeavingBuilder&&
attachToLeadPort (ProcNode& lead, uint portNr)
{
if (leadPorts.size() >= FAN_I)
throw err::Logic{_Fmt{"Builder: attempt to add further input, "
"but all %d »input slots« of the processing function are already connected."}
% FAN_I
};
PortRef portRef{lead.getPort (portNr)};
leadPorts.append (portRef);
ENSURE (leadPorts.size() <= N); /////////////////////////////////////OOO must throw exception here, since bounds can be violated by API usage
return move(*this);
}
@ -390,6 +401,11 @@ namespace engine {
WeavingBuilder&&
appendBufferTypes (uint cnt)
{
if (buffTypes.size()+cnt > FAN_O)
throw err::Logic{_Fmt{"Builder: attempt add %d further output buffers, "
"while %d of %d possible outputs are already connected."}
% cnt % buffTypes.size() % FAN_O
};
while (cnt--)
buffTypes.emplace_back([](BufferProvider& provider)
{ return provider.getDescriptor<BU>(); });
@ -400,7 +416,6 @@ namespace engine {
WeavingBuilder&&
fillRemainingBufferTypes()
{
auto constexpr FAN_O = FunSpec::FAN_O;
using BuffO = typename FunSpec::BuffO;
uint cnt = FAN_O - buffTypes.size();
return appendBufferTypes<BuffO>(cnt);
@ -409,10 +424,14 @@ namespace engine {
WeavingBuilder&&
connectRemainingInputs (DataBuilder<POL, ProcNodeRef>& knownLeads, uint defaultPort)
{
auto constexpr FAN_I = FunSpec::FAN_I;
REQUIRE (leadPorts.size() <= FAN_I);
uint cnt = FAN_I - leadPorts.size();
REQUIRE (leadPorts.size() + cnt <= knownLeads.size()); ////////////////////OOO determine if this should also be rather an exception?
if (FAN_I > knownLeads.size())
throw err::Logic{_Fmt{"Builder: attempt to auto-connect %d further »input slots«, "
"but this ProcNode has only %d predecessor nodes, while the "
"given processing function expects %d inputs."}
% cnt % knownLeads.size() % FAN_I
};
while (cnt--)
attachToLeadPort (knownLeads[leadPorts.size()], defaultPort);
return move(*this);

View file

@ -40,11 +40,12 @@ namespace test {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1367 : Dummy / Placeholder
using NoArg = std::array<char*, 0>;
using SoloArg = std::array<char*, 1>;
/** @todo a placeholder operation to wire a prototypical render node
*/
inline void
dummyOp (SoloArg in, SoloArg out)
dummyOp (NoArg in, SoloArg out)
{
UNIMPLEMENTED ("a sincerely nonsensical operation");
}

View file

@ -13196,9 +13196,7 @@
</node>
<node COLOR="#990000" CREATED="1518658696759" FOLDED="true" ID="ID_68856104" MODIFIED="1533608413694">
<richcontent TYPE="NODE"><html>
<head>
</head>
<head/>
<body>
<p>
Regel-Parametrisierung
@ -13604,9 +13602,7 @@
<icon BUILTIN="button_ok"/>
<node CREATED="1522807009051" ID="ID_578310400" MODIFIED="1522807052395">
<richcontent TYPE="NODE"><html>
<head>
</head>
<head/>
<body>
<p>
f&#252;r <i>LocationQuery</i>
@ -14302,9 +14298,7 @@
<node CREATED="1519357238119" ID="ID_490731063" MODIFIED="1519357248970" TEXT="Namen sind Platzhalter-Symbole"/>
<node CREATED="1519357249702" ID="ID_1135871152" MODIFIED="1519357313101">
<richcontent TYPE="NODE"><html>
<head>
</head>
<head/>
<body>
<p>
um eine <i>Position</i>&#160;zu kennzeichnen
@ -15620,9 +15614,7 @@
</node>
<node CREATED="1504832413997" ID="ID_439230153" MODIFIED="1576282358110" TEXT="namentlich bekannte Definitionen">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
....anders als im Diff-Framework
@ -18060,9 +18052,7 @@
<icon BUILTIN="button_ok"/>
<node CREATED="1625072904888" ID="ID_373040535" MODIFIED="1625072974106" TEXT="pa&#xdf;t nicht recht in den Gtk-Standard">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
...denn GTK geht von einer fixen Mindestgr&#246;&#223;e aus, einem Allocation-Request und dann einer Platzzuteilung
@ -48782,9 +48772,7 @@
<icon BUILTIN="help"/>
<node CREATED="1475355925880" ID="ID_464242009" MODIFIED="1576282358009" TEXT="...analog zur &quot;mark&quot;-Nachricht">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<ul>
<li>
@ -49421,9 +49409,7 @@
<node CREATED="1618496875438" ID="ID_1506165136" MODIFIED="1618496888277" TEXT="entspricht genau der Situation in einem LR-Parser"/>
<node CREATED="1618496888986" ID="ID_1950167576" MODIFIED="1618497035456" TEXT="l&#xe4;uft auf einen Table-driven-Approach hinaus">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
Auf theoretischer Ebene handel es sich um eine (nicht notwendigerweise deterministische) State-Machine. Allerdings ist diese sehr breit, und daher nicht sinnvoll direkt zu konstruieren. Wohingegen eine Tabellen-Implementierung aus Regeln dynamisch populiert werden kann
@ -49794,9 +49780,7 @@
<node CREATED="1450390181806" ID="ID_61666430" MODIFIED="1557498707235" TEXT="es registriert beim Bus-Mater einen Link zum zugeh&#xf6;rigen Tangible"/>
<node CREATED="1448406994860" ID="ID_846198635" MODIFIED="1557498707235">
<richcontent TYPE="NODE"><html>
<head>
</head>
<head/>
<body>
<p>
Kennzeichen ist die <b>EntryID</b>&#160;des zugeh&#246;rigen Elements
@ -49903,9 +49887,7 @@
<node CREATED="1481414434148" ID="ID_333480677" MODIFIED="1518487921090" TEXT="BusTerm ist stateless"/>
<node CREATED="1481414477766" ID="ID_695637715" MODIFIED="1576282358005" TEXT="soll auch so bleiben">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
ich will nicht damit anfangen, da&#223; man einen Zeiger umsetzen kann....
@ -49977,9 +49959,7 @@
<icon BUILTIN="button_ok"/>
<node CREATED="1535835597691" ID="ID_218241863" MODIFIED="1576282358004" TEXT="wird relevant bei Richtungs-Wechsel">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
Beispiel:
@ -50124,9 +50104,7 @@
</node>
<node COLOR="#435e98" CREATED="1453545812389" FOLDED="true" HGAP="43" ID="ID_202253849" MODIFIED="1576282358002" TEXT="Core-Services" VSHIFT="2">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<head/>
<body>
<p>
konzeptionell: fertig
@ -90405,8 +90383,8 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1729872260939" ID="ID_1699716079" MODIFIED="1729872282289" TEXT="Kollaboration zwischen PortBuilder und WeavingBuilder">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1729872260939" ID="ID_1699716079" MODIFIED="1729908040734" TEXT="Kollaboration zwischen PortBuilder und WeavingBuilder">
<icon BUILTIN="button_ok"/>
<node CREATED="1729872286056" ID="ID_100746695" MODIFIED="1729872380469" TEXT="nur WeavingBuilder kennt die aktuell gesammelten Daten">
<icon BUILTIN="idea"/>
</node>
@ -90415,7 +90393,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node COLOR="#338800" CREATED="1729872477774" ID="ID_1153908881" MODIFIED="1729872484078" TEXT="draft-Impl">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#fafe99" COLOR="#fa002a" CREATED="1729872485165" ID="ID_802272593" MODIFIED="1729872496094" TEXT="Logik/Assertion-Fehler">
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1729872485165" ID="ID_802272593" MODIFIED="1729907926597" TEXT="Logik/Assertion-Fehler">
<richcontent TYPE="NOTE"><html>
<head/>
<body>
@ -90423,15 +90401,48 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
PRECONDITION: weaving-pattern-builder.hpp:415: thread_1: connectRemainingInputs: (leadPorts.size() + cnt &lt;= knownLeads.size())
</p>
</body>
</html></richcontent>
<icon BUILTIN="broken-line"/>
<node CREATED="1729903816677" ID="ID_831630296" MODIFIED="1729903894592" TEXT="ist korrekt, bzw. Fehler im Test-Setup">
<richcontent TYPE="NOTE"><html>
<head/>
<body>
<p>
wir definieren eine Quell-Node ohne Vorg&#228;nger, aber binden eine Funktion mit einem Input-Slot
</p>
</body>
</html>
</richcontent>
<icon BUILTIN="broken-line"/>
</node>
<node CREATED="1729907754006" ID="ID_1996711950" MODIFIED="1729907772229" TEXT="brauche weitere Test-Funktion ohne Input-Slots"/>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1729907941427" ID="ID_217010417" MODIFIED="1729908117472" TEXT="eigentlich brauchen wir auto-Detection einer reinen Quell-Funktion">
<richcontent TYPE="NOTE"><html>
<head/>
<body>
<p>
...doch dazu ist das ganze Introspection-Schema f&#252;r die processing-Function (im Moment) viel zu starr
</p>
</body>
</html>
</richcontent>
<linktarget COLOR="#c109a3" DESTINATION="ID_217010417" ENDARROW="Default" ENDINCLINATION="224;9;" ID="Arrow_ID_19503321" SOURCE="ID_1311118655" STARTARROW="None" STARTINCLINATION="88;10;"/>
<icon BUILTIN="hourglass"/>
</node>
</node>
<node BACKGROUND_COLOR="#f8f1cb" COLOR="#a50125" CREATED="1729872353115" ID="ID_1517952001" MODIFIED="1729872368574" TEXT="diese braucht wiederzum Zugriff auf die bekannten Leads ">
</node>
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#300f69" CREATED="1729872353115" ID="ID_1517952001" MODIFIED="1729907844038" TEXT="diese braucht wiederzum Zugriff auf die bekannten Leads ">
<icon BUILTIN="messagebox_warning"/>
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1729872370117" ID="ID_1303245640" MODIFIED="1729872374635" TEXT="unsch&#xf6;n?">
<icon BUILTIN="help"/>
<node COLOR="#ac018b" CREATED="1729907777393" ID="ID_1879213616" MODIFIED="1729908057529" TEXT="ja aber woanders is auch Schei&#xdf;e">
<icon BUILTIN="smiley-oh"/>
</node>
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1729907794423" ID="ID_190339337" MODIFIED="1729907822402" TEXT="(hier besteht eine gef&#xe4;hrlich enge Kopplung)">
<icon BUILTIN="messagebox_warning"/>
</node>
<node CREATED="1729908078587" ID="ID_1311118655" MODIFIED="1729908124722" TEXT="ungutes Bauchgef&#xfc;hl....">
<arrowlink COLOR="#c109a3" DESTINATION="ID_217010417" ENDARROW="Default" ENDINCLINATION="224;9;" ID="Arrow_ID_19503321" STARTARROW="None" STARTINCLINATION="88;10;"/>
</node>
</node>
</node>
</node>
@ -90440,8 +90451,8 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node COLOR="#338800" CREATED="1729872416670" ID="ID_106035391" MODIFIED="1729872433250" TEXT="incl. Definieren zus&#xe4;tzlicher Leads on-the-fly">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1729872434676" ID="ID_1193395658" MODIFIED="1729872439652" TEXT="Fehler-Checks">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1729872434676" ID="ID_1193395658" MODIFIED="1729908033526" TEXT="Fehler-Checks">
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>