4 ms·
There are many other features of PL/I besides those mentioned there, which are not encountered in modern languages. Because PL/I was designed by IBM for their
by adrian_b 5y ago
There are many other features of PL/I besides those mentioned there, which are not encountered in modern languages.
Because PL/I was designed by IBM for their computers and operating systems, there were no concerns for portability, so the language definition included a large amount of features that are left unspecified in standards for languages like C/C++, because they are available only for certain operating systems or computers, so the standard must be restricted to specify only the minimum features that are available everywhere.
For example the C++ threads are limited only to the features provided by the POSIX pthreads, even if most operating systems have additional features for multi-threading. PL/I on the other hand, already in 1965 had more powerful features than the C++ threads.
One feature of PL/I that is completely absent in all modern languages is what I consider to be the right way for error handling.
Instead of being forced to test the return value of a function to determine what error might have happened, which is a redundant operation, as this was already tested once in the invoked function, and which clutters the code, obscuring the processing of the normal path, the PL/I method was to group the error handlers at the end and pass the labels of the error handlers to the invoked function as alternative return labels.
While this looks visually very similar to a try block with exception handlers, the hardware implementation in PL/I is far more efficient than in modern languages, because there are no conditional branches and no extra code to determine where is the appropriate error handler, just the return, which is done anyway when the invoked function finishes, jumps to different addresses in case of errors, instead of returning to the point of invocation.
PL/I also had exceptions, but those were used for really exceptional conditions, like numeric overflow, illegal memory accesses etc., not for correctable error conditions, like a mistyped user input or a file that cannot be found, which are best handled at the point where a function has been invoked, because only there you have complete information about the intention of the failed operation.
- p_l 5y agoPL/I model was inspiration for Common Lisp condition system, which handles both recoverable (continuable) and non-recoverable conditions (akin to exceptions). Continuable exceptions are also a thing in Windows NT, though rarely seen in practice. All of those hark back to PL/I error handling, possibly through Project MAC (which was probably bigger PL/I user than anything from IBM for a time)
- froh 5y agoSomehow I find it fitting to quote the Britannica on Project MAC: https://www.britannica.com/topic/Project-Mac https://www.britannica.com/topic/Project-Mac "Project MAC, in full Project on Mathematics and Computation, a collaborative computer endeavour in the 1960s that sought to to create a functional time-sharing system. Project MAC, founded in 1963 at the Massachusetts Institute of Technology (MIT), was funded by the U.S. Department of Defense’s Advanced Research Projects Agency (ARPA) and the National Science Foundation. The goal for the project was to allow many users access to the programs of a single computer from various locations. Project MAC’s pioneering exploration of the working methods of multiple-user access became a foundation for modern computer networking and online collaboration."
- PaulDavisThe1st 5y ago> For example the C++ threads are limited only to the features provided by the POSIX pthreads, even if most operating systems have additional features for multi-threading. What facilities are you thinking of? > PL/I on the other hand, already in 1965 had more powerful features than the C++ threads. Given that the term "threads" originates in the 65/66/67 era, this is an interesting claim.
- adrian_b 5y agoThe term "thread" has become fashionable only after 1990. Nobody used the terms "thread" or "multi-threading" when PL/I was designed. Everybody used the terms "task" and "multi-tasking", with the same meaning. So in PL/I you have "tasks" for what are now called "threads". The most annoying feature of the C++ thread support library, which is inherited from the POSIX pthreads specification, is the pathetic operation join which waits for the termination of a designated thread. This is almost never what you want. The most frequent case is to wait for the termination of anyone of a group of threads, which cannot be done with join. Already in 1965, PL/I had a wait that could do anything that can be done with WaitForMultipleEvents/WaitForSingleEvent, i.e. it could wait for any or all of any combinations of a set of events, e.g. thread terminations. This is such a basic feature that I cannot understand how it could have been omitted from the POSIX pthreads and in consequence also from the C++ thread support library. The other features of pthreads/C++ that can be used to implement such a functionality, e.g. condition variables, also suck badly in comparison with a good wait for events.
- PaulDavisThe1st 5y agoIt's clear that you know a lot about this stuff, but I think maybe not quite enough. The Linux kernel retains the term "task" for "execution context", and the term "thread" is used exclusively in user space purely because of programmer conventions (pthreads, specifically). This makes a limited amount of of sense because "thread" has also come to mean things that are very definitely not full execution tasks (user-space and/or so-called "green" threads). This overloading of the terminology in user-space is not reflected in kernels, but allows for developers to play with alternate implementations without changing their fundamental terminology. After all, there some things where user-space threads are precisely what you want (and these absolutely do not correspond to kernel tasks). > This is almost never what you want. I would beg to differ. I've been writing multithreaded code in C++ for nearly 30 years, and I don't remember any time that I wanted to join on a group of threads. My current project (20 years old) is heavily multithreaded (typically 20-60 threads) and there is nowhere that a thread primitive to join on a group of threads would make our lives easier. The only context where I could even think of using it might be to wait on a thread pool, but in general this tends to be unnecessary and if it is, can be trivially handled without a multi-join. > Already in 1965, PL/I had a wait that could do anything that can be done with WaitForMultipleEvents/WaitForSingleEvent, WaitForMultipleEvents/WaitForSingleEvent are not part of the C or C++ language, but Windows system calls. While their semantics are very powerful and useful (which obviously would thus apply to PL/1's wait), their absence cannot be laid at the feet of C or C++: no Unix-like OS has had this operation, ever (it is almost possible with contemporary Linux). You could make the argument that it's not part of pthreads because this operation was never a part of posix, and so pthreads could not build on it (you can use those calls on Windows even in a single-threaded task, and that would be true in a POSIX system if the call existed). So it really has almost nothing to do with pthreads at all, other than that one could imagine a pthread wanting to block on "wait-for-something-anything".
- pjc50 5y ago> the PL/I method was to group the error handlers at the end and pass the labels of the error handlers to the invoked function as alternative return labels. The idea of an alternative return address - that is, allow the calling convention to pass more than on return instruction pointer - seems both simple to implement and really useful. I guess in the modern gotoless world the trouble is structuring the syntax around the call.
- adrian_b 5y agoThe alternative return addresses were declared in the function prototype as parameters having the type label. Then you just passed them during function call, e.g. "handle = open_file(input_file_name, open_flags, FailedToOpenInputFile);" The error handlers at the end of the body of the invoking function were just labelled appropriately. Writing a label like FailedToOpenInputFile: before an error handler is certainly much simpler and more obvious than strange workarounds for exception identification, like inventing a dedicated data type for each possible error, as in C++.
- catern 5y agoIt would be nice if those labeled blocks could be written inline and anonymously - just pass a block as an argument rather than having to actually name the error handling block. Is that supported?
- adrian_b 5y agoNot in PL/I or in the other languages with this feature (ALGOL 60, FORTRAN IV). This could be an easy syntax extension, but then the only advantage remains the more efficient hardware implementation of the error handling. In that case you no longer have the separation in program text between the normal execution path and the error handlers, which removes visual clutter.
- gnufx 5y agoYou can pass a fatal error-handling routine to a Fortran subprogram, to be called with the error code.
- gnufx 5y agoIs the PL/I alternate return fundamentally different from Fortran's (or FORTRAN's in those days)?
- adrian_b 5y agoIt was the same as in many FORTRAN IV dialects and also in ALGOL and in many other early languages, but in FORTRAN that was not a standard language feature, even if many compilers implemented it as a language extension.
- gnufx 5y agoI was responding to "completely absent in all modern languages". Alternate return has been in the standard since '77, and Fortran 2018 seems modern enough.
- adrian_b 5y agoYou are right that alternate return labels have been included in more recent FORTRAN standards. Nevertheless, this feature is much less useful in FORTRAN than in laguages like PL/I, because the FORTRAN labels are restricted to numbers. Unless you use a preprocessor, you cannot give descriptive names to the error handlers, so the equivalent FORTRAN code looks much uglier than in PL/I.
- gnufx 5y agoIn which FORTRAN IV dialects was it the same as in PL/I? I should have said that alternate return is obsolescent in recent Fortran, and I don't remember ever feeling the need to use it, at least for error-handling.
- ratboy666 5y agoIn FORTRAN IV, multiple return labels could be passed to a subroutine. This was carried into PL/I. In FORTRAN 66, this was not supported. But, FORTRAN IV and 66 both support assigned go to, which can be used to replace this -- WATFIV supported this (local routines that use ASSIGN, with a bit of syntax sugar). Note that this is a LONG time ago (mid sixties)...
- ratboy666 5y agoAnd... for reference. In my Microsoft F80 github string repository: https://github.com/ratboy666/string https://github.com/ratboy666/string (Microsoft F80 was a FORTRAN 66, slightly subset compiler -- no COMPLEX that Microsoft sold from the late 70s to early 80s). In there find pop.mac which is a short 4 byte assembly routine to discard a stack level. That can be used as follows: ASSIGN 1 TO I -- STORE ADDRESS OF LABEL 1 TO I CALL F(I) -- PASS I TO SUBROUTINE F ... -- WE WILL NEVER GET HERE 1 ... SUBROUTINE F(I) EXTERNAL $POP INTEGER $POP JUNK = $POP(0) -- REMOVE RETURN ADDRESS GO TO I -- GO TO ASSIGNED LABEL I END The ASSIGN command puts the address of label 1 into INTEGER I GO TO I then transfers to that location. Note that we can pass I into the SUBROUTINE, use $POP to remove a stack level (the return address), then jump to the variable. Scheme is nicer, which continuations, of course, but that hadn't been considered yet... The ASSIGN was deleted as a feature in FORTRAN 95 -- obsolescent by FORTRAN 90. I guess "very very old-school". Now, the FORTRAN 66 standard doesn't mention if something like this is allowed... but, since no stack was involved in early implementations, and recursion was not allowed, I imagine that it would work more widely than might otherwise be expected.
- josephg 5y ago> the PL/I method was to group the error handlers at the end and pass the labels of the error handlers to the invoked function as alternative return labels. Huh. I wonder if it would be possible to modify LLVM to support this for rust. You'd be inlining the match / try / unwrap() calls that usually happen after returning from a method which returns an enum variant. And you'd be inlining it across the function call boundary. This would change the calling convention for methods that return enum variants, but rust doesn't publish a calling convention yet anyway. And for internal only methods, this might be a significant performance win in IO-heavy workloads. You might need some complex heuristics to figure out when this is worth it though. Not all enums are Option / Result. I bet plenty functions are faster without this trick. And if you jump based on the value in a register, is this fast in modern CPUs? How would that compare to making a high prediction accuracy branch?
- volta83 5y agoYou mean "multi-return" functions? https://github.com/bytecodealliance/wasmtime/issues/1057 https://github.com/bytecodealliance/wasmtime/issues/1057 We have looked at these before. Modern CPUs have a RAS, and you dont want to mess with that. But there are ways to implement this, and some papers that cover the performance impact. We'd need a very motivated individual to add support for this to LLVM and Cranelift.
- tux3 5y agoRAS: Return Address Stack, a simple predictor that tracks return addresses.
- adrian_b 5y agoThe fact that the indirect jump that returns when an error is encountered is not predicted, is never worse than when testing an error code returned by the function, because that conditional jump is also always mispredicted. The method used by modern languages requires both an indirect jump for return, hopefully predicted, and a mispredicted conditional jump. Moreover, if the invoking function is executed once more, but the next time there is no error, the conditional jump that tests the error code may be mispredicted once more. Using multiple return labels requires only a single mispredicted unconditional jump and it also omits a bunch of redundant instructions for generating an error code and testing it. For functions that may encounter multiple types of errors, the economy is much larger because testing the returned error code would have needed either multiple conditional branches or an indirect indexed jump for a switch/case structure.
- ngcc_hk 5y ago> Because PL/I was designed by IBM for their computers and operating systems, there were no concerns for portability, so the language definition included a large amount of features that are left unspecified in standards for languages like C/C++, because they are available only for certain operating systems or computers, so the standard must be restricted to specify only the minimum features that are available everywhere. Reading wiki I am not sure the assertion is right. In fact I am not sure even the first set of statements is right. It was involved a lot of others from beginning (from users in share/guide) to other universities and European standard committees.
- adrian_b 5y agoAlmost all PL/I features have already been present in an internal technical report about NPL (New Programming Language) from December 1964, which was done by an IBM team, concurrently with the software design for the new IBM System/360 series of computers, for which PL/I was intended to be the main programming language. The design of the new language has taken into account the feedback from the users of FORTRAN IV and COBOL on the previous 7xxx series of IBM computers and it was also inspired by features from ALGOL 60, but otherwise there was no direct influence of outsiders on the language design. Around 1966, a few extra features were added to PL/I, the most important being pointers and unions, which were taken from the Hoare and McCarthy proposals for the successor of ALGOL 60. At that time IBM did not care yet if any of their programming languages will also be used on other computers. They were a hardware vendor, which offered as a bonus operating systems and programming languages with their computers, to convince the customers to buy the hardware. They were not selling software yet. Compatibility with other hardware was not at all desirable for IBM. Only the other smaller companies were interested in porting IBM languages like FORTRAN or PL/I to their computers, to make them an acceptable alternative to IBM hardware. So the standardization efforts were done in other places, but based on the de facto standards created by the IBM products.
- mdmi 5y agoThe "error handling" feature is a particular use of nonlocal GOTO plus a LABEL data type. It may be more efficient than an exception, because a label value includes its stack frame, while an exception must check whether the exception is handled in each frame as the stack is unwound. On the downside, label variables entail the danger of jumping to an uninitialized or dead label value. This is a counterexample to another comment's claim that PL/I is a "safe" language.