Skip to content

Commit 3a1fd1a

Browse files
committed
Add spawning function qualifier to type system (issue #15)
1 parent da59804 commit 3a1fd1a

File tree

2 files changed

+132
-26
lines changed

2 files changed

+132
-26
lines changed

reduction.tex

+131-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\clause{Reduction types}
1+
\clause{Reduction and spawning function types}
22
\sclause{Introduction}
33

44
\pnum
@@ -16,6 +16,14 @@
1616
and either thread or allocated storage duration
1717
results in undefined behavior.
1818

19+
\pnum
20+
The \tcode{_Task _Call}
21+
qualifier
22+
(also called the ``spawning function qualifier")
23+
is in a new syntactic category for qualifiers of function types.
24+
It can be used to write functions that can spawn tasks
25+
and return while some of those tasks are still running.
26+
1927
\sclause{Reduction specifiers}
2028
\ssclause*{Syntax}
2129

@@ -544,6 +552,49 @@
544552
so undefined behavior results if it used as if it did.
545553
\end{example}
546554

555+
\sclause{Spawning function types}
556+
557+
\ssclause*{Syntax}
558+
559+
\begin{bnf}
560+
\nontermdef{spawning-function-qualifier}
561+
\br
562+
\terminal{_Task}
563+
\terminal{_Call}
564+
\end{bnf}
565+
566+
\ssclause*{Constraints}
567+
568+
\pnum
569+
A call to a function with spawning function type
570+
shall appear only within a task spawning call statement.
571+
572+
\ssclause*{Semantics}
573+
574+
\pnum
575+
A function whose declarator
576+
includes a spawning function qualifier
577+
has spawning function type.
578+
Such a function may return to its caller
579+
while some of its spawned tasks are still executing.
580+
581+
\begin{example}
582+
~\\
583+
\begin{verbatim}
584+
int f(void) _Task _Call;
585+
int (*g1(void) _Task _Call)(void);
586+
int (*g2(void))(void) _Task _Call;
587+
\end{verbatim}
588+
589+
\tcode{f} is declared to be a spawning function
590+
returning \tcode{int}.
591+
\tcode{g1} is declared to be a spawning function
592+
returning a pointer to a (non-spawning) function.
593+
\tcode{g2} is declared to be a (non-spawning) function
594+
returning a pointer to a spawning function.
595+
596+
\end{example}
597+
547598
\sclause{Integration with the C standard}
548599

549600
Change paragraph 7 of subclause 6.2.1 ``Scopes of identifiers":
@@ -577,7 +628,8 @@
577628
\end{quote}
578629

579630
Add a new item
580-
to the list in paragraph 20 of subclause 6.2.5 ``Types":
631+
to the list in paragraph 20 of subclause 6.2.5 ``Types"
632+
(following the item for union types):
581633

582634
\begin{quote}
583635
\begin{itemize}
@@ -593,6 +645,27 @@
593645
\end{itemize}
594646
\end{quote}
595647

648+
Change sub-bullet of paragraph 20 of subclause 6.2.5:
649+
650+
\begin{quote}
651+
\begin{itemize}
652+
\item
653+
A \textit{function type}
654+
describes a function
655+
with specified return type.
656+
A function type is characterized
657+
by its return type\added{,} \removed{and}
658+
the number and types of its parameters
659+
\added{and its set of function qualifiers}.
660+
A function type is said to be derived from its return type,
661+
and if its return type is $T$,
662+
the function type is sometimes called
663+
``function returning $T$".
664+
The construction of a function type from a return type
665+
is called ``function type derivation".
666+
\end{itemize}
667+
\end{quote}
668+
596669
Change the grammar rule in subclause 6.4.1 ``Keywords",
597670
by adding new alternatives:
598671

@@ -714,7 +787,7 @@
714787
or enumeration content. ...
715788
\end{quote}
716789

717-
Change paragraph 9 of 6.7.2.3 ``Tags":
790+
Change paragraph 9 of 6.7.2.3:
718791

719792
\begin{quote}
720793
If a type specifier of the form
@@ -741,6 +814,32 @@
741814
and does not redeclare the tag.
742815
\end{quote}
743816

817+
Change the grammar rule in subclause 6.7.6
818+
``Declarators":
819+
820+
\begin{quote}
821+
\begin{bnf}
822+
\nontermdef{direct-declarator}
823+
\br
824+
...
825+
\br
826+
direct-declarator \terminal{(} parameter-type-list \terminal{)}
827+
\added{function-qualifiers\opt}
828+
\br
829+
...
830+
\end{bnf}
831+
\end{quote}
832+
833+
Add a new grammar rule to 6.7.6:
834+
835+
\begin{quote}
836+
\begin{bnf}
837+
\nontermdef{function-qualifiers}
838+
\br
839+
spawning-function-qualifier
840+
\end{bnf}
841+
\end{quote}
842+
744843
Change paragraph 1 of subclause 6.7.6.3
745844
``Function declarations (including prototypes)":
746845

@@ -750,14 +849,41 @@
750849
\added{or a reduction type}.
751850
\end{quote}
752851

753-
Add a new paragraph following paragraph 8 of subclause 6.7.6.3
754-
``Function declarations (including prototypes)":
852+
Add a new paragraph following paragraph 8 of subclause 6.7.6.3:
755853

756854
\begin{quote}
757855
A declaration of a parameter as a reduction type
758856
shall be adjusted to be a pointer to the same reduction type.
759857
\end{quote}
760858

859+
Change paragraph 15 of subclause 6.7.6.3:
860+
861+
\begin{quote}
862+
For two function types to be compatible,
863+
both shall specify compatible
864+
return types\removed{.}\added{,}$^{146)}$
865+
\added{and both shall specify equivalent
866+
sets of function qualifiers.}
867+
Moreover, the parameter type lists, if both are present, shall agree in the number of
868+
parameters and in use of the ellipsis terminator; corresponding parameters shall have
869+
compatible types.
870+
...
871+
\end{quote}
872+
873+
Change the grammar rule in subclause 6.7.7 ``Type names":
874+
875+
\begin{quote}
876+
\begin{bnf}
877+
\nontermdef{direct-abstract-declarator}
878+
\br
879+
...
880+
\br
881+
direct-abstract-declarator\opt{}
882+
\terminal{(} parameter-type-list\opt{} \terminal{)}
883+
\added{function-qualifiers\opt}
884+
\end{bnf}
885+
\end{quote}
886+
761887
Add a new paragraph following paragraph 8
762888
of subclause 6.7.9 ``Initializers":
763889

spawning.tex

+1-21
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
the associated task block is the smallest enclosing task block statement
6262
or parallel loop.
6363
Otherwise, for a statement within the body of a function
64-
declared with the spawning function specifier,
64+
with spawning function type,
6565
the associated task block is the same as it was
6666
at the point of the task spawning call statement
6767
that invoked the spawning function.
@@ -171,23 +171,3 @@
171171
might invoke more than one spawning function,
172172
or might invoke none.
173173
\end{note}
174-
175-
\sclause{The spawning function specifier}
176-
\ssclause*{Syntax}
177-
\pnum
178-
A new alternative is added to the grammar of function specifier
179-
(6.7.4 paragraph 1):
180-
181-
\begin{bnf}
182-
\nontermdef{function-specifier}
183-
\br
184-
\terminal{_Task} \terminal{_Call}
185-
\end{bnf}
186-
187-
\ssclause*{Constraints}
188-
\pnum
189-
If a spawning function specifier appears
190-
on any declaration of a function,
191-
it shall appear on every declaration of that function.
192-
A function declared with a spawning function specifier
193-
shall be called only from a task spawning call statement.

0 commit comments

Comments
 (0)